Restrict target ranges

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
569
Office Version
  1. 365
Platform
  1. Windows
I have a large spreadsheet and I have a macro in the worksheet to color the active row and column. I have figured out how to restrict the color application on the columns. When I select a cell, the row is highlighted from column A to column DP. However I cannot figure out how to restrict the rows in a specific column from 1 to 150 to be highlighted. I have my macro code pasted below. How can I restrict the number of rows highlighted in a particular column?

VBA Code:
Dim MyRow As Integer
Dim MyCol As Integer

MyRow = ActiveCell.Row
MyCol = ActiveCell.Column

If MyCol < 120 And Target.Row < 304 Then

    Cells.Interior.ColorIndex = xlColorIndexNone
    Range("A" & MyRow & ":DP" & MyRow).Interior.Color = RGB(115, 240, 255)
    Target.EntireColumn.Interior.Color = RGB(115, 240, 255)
    Target.Interior.ColorIndex = xlColorIndexNone

End If

Thanks for the Help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How about
VBA Code:
Cells(1, Target.Column).Resize(304).Interior.Color = RGB(115, 240, 255)
 
Upvote 0
Perfect! Thanks for the quick response. It works perfectly now.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,135
Messages
6,123,239
Members
449,093
Latest member
Vincent Khandagale

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