Hi, can anyone help me with this bit of code shown below (The code below forms part of a larger code) What it's suppose to do is add color to columns A-H. It runs but it will only add color to column A. Where have I gone wrong?
Note: S and L are = Dim L As Range / Dim S As Range
Many thanks
Code:
With ActiveSheet.Range("A13:H50")
Set S = Cells.Find("Small", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not S Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
End If
Set L = Cells.Find("Large", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not L Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
End If
End With
The only way I can get it to work is if I write the code in the following way:
With ActiveSheet.Range("A13:H50")
Set S = Cells.Find("Small", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not S Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 2), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 3), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 4), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 5), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 6), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 7), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 8), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
End If
Set L = Cells.Find("Large", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not L Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 2), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 3), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 4), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 5), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 6), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 7), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 8), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
End If
End With
Note: S and L are = Dim L As Range / Dim S As Range
Many thanks
Code:
With ActiveSheet.Range("A13:H50")
Set S = Cells.Find("Small", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not S Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
End If
Set L = Cells.Find("Large", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not L Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
End If
End With
The only way I can get it to work is if I write the code in the following way:
With ActiveSheet.Range("A13:H50")
Set S = Cells.Find("Small", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not S Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 2), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 3), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 4), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 5), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 6), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 7), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
ActiveSheet.Range(Cells(13, 8), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 3
End If
Set L = Cells.Find("Large", MatchCase:=True, lookat:=xlWhole, LookIn:=xlValues)
If Not L Is Nothing Then
ActiveSheet.Range(Cells(13, 1), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 2), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 3), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 4), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 5), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 6), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 7), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
ActiveSheet.Range(Cells(13, 8), Cells(13, 8)).End(xlDown).Interior.ColorIndex = 4
End If
End With