Hello all.
I'm trying to create a macro to conditionally format a range of cells depending on a set of criteria in the worksheet. The set up of the sheet is as follows and there are more than 3 criteria
A B C .... AH
1 Primary
2 Secondary
3 Tertiary
4 Secondary
Column AH contains the criteria such that e.g. if AH1="Primary" then range A1:E1 cell's colour will be red and make the font white and if cell AH1 = "Secondary" then colour cells range A1:E1 yellow and make the font black THEN if e.g. AH2="Primary" then range A2:E2 will have the criteria applied etc...
I've come up with this code so far but I need to implement a looping structure to go through the whole range and I'm a bit stuck - any ideas? (The line Set criteria = ActiveCell.Offset(rowOffset:=0, columnOffset:=33).Value doesn't work btw but its work in progress)
Sub Condform()
Worksheets("Sheet1"
.Activate
Worksheets("Sheet1"
.Range("A1"
.Select
Dim icolor As Integer
Dim fcolor As Integer
Dim criteria As Range
Dim Target As Range
Set Target = Worksheets("Sheet1"
.Range("A1:G155"
Set criteria = ActiveCell.Offset(rowOffset:=0, columnOffset:=33).Value
Select Case criteria
Case "Primary"
icolor = 3
fcolor = 2
Case "Secondary"
icolor = 6
fcolor = 1
End Select
Target.Interior.ColorIndex = icolor
Target.Font.ColorIndex = fcolor
End Sub
Hopefully I've explained well enough
I'm trying to create a macro to conditionally format a range of cells depending on a set of criteria in the worksheet. The set up of the sheet is as follows and there are more than 3 criteria
A B C .... AH
1 Primary
2 Secondary
3 Tertiary
4 Secondary
Column AH contains the criteria such that e.g. if AH1="Primary" then range A1:E1 cell's colour will be red and make the font white and if cell AH1 = "Secondary" then colour cells range A1:E1 yellow and make the font black THEN if e.g. AH2="Primary" then range A2:E2 will have the criteria applied etc...
I've come up with this code so far but I need to implement a looping structure to go through the whole range and I'm a bit stuck - any ideas? (The line Set criteria = ActiveCell.Offset(rowOffset:=0, columnOffset:=33).Value doesn't work btw but its work in progress)
Sub Condform()
Worksheets("Sheet1"
Worksheets("Sheet1"
Dim icolor As Integer
Dim fcolor As Integer
Dim criteria As Range
Dim Target As Range
Set Target = Worksheets("Sheet1"
Set criteria = ActiveCell.Offset(rowOffset:=0, columnOffset:=33).Value
Select Case criteria
Case "Primary"
icolor = 3
fcolor = 2
Case "Secondary"
icolor = 6
fcolor = 1
End Select
Target.Interior.ColorIndex = icolor
Target.Font.ColorIndex = fcolor
End Sub
Hopefully I've explained well enough