Coloring active cell & rows existing code edit

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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