vba - How to conditional format data in multiple columns by hardcoding what the column's header name is? -


I am looking to run a series of conditional formatting rules on two columns of data. I know that I can select a column sheet and all the cells in that column, but to make my macro more complete proof I want to search for it in the column headers and on the cells below two specific headers I want to run the formatting.

I have used record macro tools at present to see how this might work, and this is my current setup. This macro works, I make it full-proof and specific I want to search through the worksheet for column title names. I would like to find a videocassette for the column heading "Header 1" and "Header 2".

  sub-two column consultancy () column ("K: AJ"). Select the selection. Add format rule type: = xlTextString, string: = "CONTAINSTEXT1", _TextOperator: = xlContains Selection. Format condition (selection.form condition.quant) .Satfestprice selections. Format Conditions (1) .folt .color = -16383844 .tintedshot = 0 end with end with Selection.FormatConditions (1) .Interior .PatternColorIndex = xlAutomatic .color = 13,551,615 .TintAndShade = 0 Selection.FormatConditions (1) .StopIfTrue = false Selection.FormatConditions.Add follows: = xlTextString, string: = "CONTAINSTEXT2", _ TextOperator: = xlContains Selection.FormatConditions (Selection.FormatConditions.Count). Selection.FormatConditions with .SetFirstPriority (1 ) .Font .color = - + 1,67,51,204 .TintAndShade = 0 with Selection.FormatConditions (1) .Interior .PatternColorIndex = xlAutomatic end .color = 10284031 Ktint Andshaid = 0 End End Sub < / Code>   

Try this:

  subpolar () range, Set the range Dim MyHaders, Header Dim Icintring String MyHeaders = Array ("Header 1", "Header 2") as the HRN ws set with ws = ThisWorkbook.Sheets ("Sheet 1") set RNG =. Range ("A1" range ("A1"). Offset (0 _, .Column.Count - 1). End (xlToLeft) .adressation) 'debug.print header. Set the address and header for each header in header fcel = rng.Find (header, rng.Cells (rng.Cells.Count)) if not, then nothing is if hrng is nothing then set hrng = fcel other sets .Entire column hrng = Union (hrng, fcel.EntireColumn) End if End if Next 'debug.print hrng.address hrng.FormatConditions.Add follows: = xlTextString, string: = "CONTAINSTEXT1", _ TextOperator: hrng. With FormatConditions (hrng.FormatConditions.Count) .Font .color = -16383844 .withTintAndShade = 0 with the end = xlContains with intervals .PettonColor Index = XLImicator Color = 13551615 .TintAndShade = 0 at the end .topIfTrue = F otherwise finished with hrng.FormatConditions.Add type = with xlTextString, String: = "CONTAINSTEXT2", _ TextOperator: hrng.FormatConditions (hrng.FormatConditions.Count) .Font .color = -16751204 .TintAndShade = 0 along with the end = xlContains with interiors. Partnroller Index = XLatamatic. Color = 10284031. Tints and terminals = 0 ends. Close = wrong end with the right end   

I have only assumed that your headers are in the first line.
Adjust the code to suit.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -