Coloring active cell & rows existing code edit

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
I use the following code to high light rows & active cells etc.

My range is A-G & currently row`s 3-28

How can this code be altered so if the row 29 or 30 is selected then the Interior cell color & active cell turn Red

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
    Dim myStartCol As String
    Dim myEndCol As String
    Dim myStartRow As Long
    Dim myLastRow As Long
    Dim myRange As Range
 
    If Target.Cells.Count > 1 Then Exit Sub
   
    Application.ScreenUpdating = False
   
    myStartCol = "A"
    myEndCol = "G"
 
    myStartRow = 3
  
    myLastRow = 28
   
    Set myRange = Range(Cells(myStartRow, myStartCol), Cells(myLastRow, myEndCol))
   
    myRange.Interior.ColorIndex = 2
   
    If Intersect(Target, myRange) Is Nothing Then Exit Sub
   
  Range(Cells(Target.Row, myStartCol), Cells(Target.Row, myEndCol)).Interior.ColorIndex = 6
Target.Interior.Color = vbGreen
    Application.ScreenUpdating = True
 
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Or other code that would work,
example.

My range is A29:G29
if a cell is selected withing my range then fill cells A29:G29 Red

Thanks.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top