ExcelNooberino
New Member
- Joined
- Jan 2, 2019
- Messages
- 43
- Office Version
- 2016
- Platform
- Windows
Hi! Hope y'all doing just fine...
So I have this problem with a recent code I'm working on. Basically I want to apply some formatting to the color off a range of cells after I run this macro I've created but it keeps telling me that there's a "Next without For" and I don't understand why... I just want something that allows me to do this.
If the cell value in column A is greater than the cell value in column B set the background to green.
If the cell value in column A is less than the cell value in column C set the background to red.
If the cell value in column A is in between the cell value B and C set the background to orange.
So far I have this (cell A is like mine Cell(i, 8).Value):
Thanks in advance!
So I have this problem with a recent code I'm working on. Basically I want to apply some formatting to the color off a range of cells after I run this macro I've created but it keeps telling me that there's a "Next without For" and I don't understand why... I just want something that allows me to do this.
If the cell value in column A is greater than the cell value in column B set the background to green.
If the cell value in column A is less than the cell value in column C set the background to red.
If the cell value in column A is in between the cell value B and C set the background to orange.
So far I have this (cell A is like mine Cell(i, 8).Value):
Code:
Dim LastRow As LongDim FirstRow As Long
LastRow = Sheet5.Range("B" & Rows.Count).End(xlUp).row
FirstRow = Sheet5.Cells(10, 8).row
If LastRow = FirstRow Then
'do nothing
Else
For i = 10 To LastRow
If Cells(i, 8).Value > Cells(i, 11).Value Then
Cells(i, 8).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5287936 'Green
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.Bold = True
End With
If Cells(i, 8).Value > Cells(i, 10).Value Then
Cells(i, 8).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255 'Red
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.Bold = True
End With
Else
Cells(i, 8).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407 'Orange
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.Bold = True
End With
End If
Next i
End If
Thanks in advance!
Last edited by a moderator: