Share via

how to shorten this code

Rajeev Raghavan 1 Reputation point
2021-08-09T20:32:34.797+00:00

Sub grey()

Last = Cells(Rows.Count, 2).End(xlUp).Row
For i = Last To 1 Step -1

If Cells(i, 2).Value = Range("T6").Value Then

Cells(i, "A").EntireRow.Resize(Range("V6").Value, 11).Select
Selection.Interior.ColorIndex = 0

End If
Next i

Selection.Interior.ColorIndex = 15

Last = Cells(Rows.Count, 2).End(xlUp).Row
For i = Last To 1 Step -1

If Cells(i, 2).Value = Range("T7").Value Then

Cells(i, "A").EntireRow.Resize(Range("V7").Value, 11).Select
Selection.Interior.ColorIndex = 0

End If
Next i

Selection.Interior.ColorIndex = 15

Last = Cells(Rows.Count, 2).End(xlUp).Row
For i = Last To 1 Step -1

If Cells(i, 2).Value = Range("T8").Value Then

Cells(i, "A").EntireRow.Resize(Range("V8").Value, 11).Select
Selection.Interior.ColorIndex = 0
End If
Next i

Selection.Interior.ColorIndex = 15

End Sub

Developer technologies | Visual Basic for Applications

1 answer

Sort by: Most helpful
  1. Bob Larson (Access MVP 2008, 2009, 2011) 251 Reputation points
    2021-08-12T18:23:37.903+00:00
    Sub grey()
    
    Last = Cells(Rows.Count, 2).End(xlUp).Row
    For i = Last To 1 Step -1
    
    If Cells(i, 2).Value = (Range("T6").Value _
    Or Cells(1, 2).Value = Range("T7").Value _
    Or Cells(1, 2).Value = Range("T8").Value) Then
    
    Cells(i, "A").EntireRow.Resize(Range("V6").Value, 11).Select
    Selection.Interior.ColorIndex = 0
    
    End If
    Next i
    
    Selection.Interior.ColorIndex = 15
    
    
    End Sub
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.