Hi subby,
Try the following tested and working code:
a. By eliminating 'Select', the other cell was not highlighted.![]()
Sub FindMax() 'MAX is an Excel KEYWORD. It is NOT RECOMMENDED to use Excel KEYWORDS as variables or function/Sub names. Dim r As Range Dim rw5 As Long For rw5 = 17 To 46 Set r = Cells(rw5, 11) If r.Value - Cells(7, 6) <= 20 And r.Value - Cells(7, 6) > 0 Then r.Interior.ColorIndex = 6 r.Font.Color = vbBlack r.Font.Bold = True End If Next rw5 'Clear object pointer Set r = Nothing End Sub
b. When you had if ... then on the same line, Excel thought the if statement was completed.
It takes a lot more space, but I almost always use the following if construction:
Lewis![]()
If a = b then c = d Endif











LinkBack URL
About LinkBacks
Register To Reply

Bookmarks