Putting conditional formatting on a page after it's created in vba

kadain

New Member
Joined
May 19, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi guys am looking to code in a condictional formatting to a newly created sheet via vba
This intales highlighting the row orange when you click on a cell between a certain range(Any range will do ill edit it to what i need)
i would just set it up when i use it my self manually but unfortantly the workbooks is for other peoples use and they are not excel friendly
Please any help would be great
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim testRange As Range
    Dim myRange As Range
    Dim selectedRow As Long
    Set testRange = Range("A:A")
    Set myRange = Selection
    If Not Intersect(testRange, myRange) Is Nothing Then
        selectedRow = ActiveCell.Row
        ActiveSheet.Rows.Interior.Color = xlNone '<== optional
        ActiveSheet.Rows(selectedRow).Interior.Color = RGB(255, 192, 0)
    End If
End Sub
 
Upvote 0
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim testRange As Range
    Dim myRange As Range
    Dim selectedRow As Long
    Set testRange = Range("A:A")
    Set myRange = Selection
    If Not Intersect(testRange, myRange) Is Nothing Then
        selectedRow = ActiveCell.Row
        ActiveSheet.Rows.Interior.Color = xlNone '<== optional
        ActiveSheet.Rows(selectedRow).Interior.Color = RGB(255, 192, 0)
    End If
End Sub
Thanks for the quick reply,

it seems to bug out at

ActiveSheet.Rows.Interior.Color = xlNone '<== optional
and when i remove that its this line that bugs

ActiveSheet.Rows(selectedRow).Interior.Color = RGB(255, 192, 0)

unsure why
 
Upvote 0
Thanks for the quick reply,

it seems to bug out at

ActiveSheet.Rows.Interior.Color = xlNone '<== optional
and when i remove that its this line that bugs

ActiveSheet.Rows(selectedRow).Interior.Color = RGB(255, 192, 0)

unsure why
Insert the provided code into the worksheet object for the worksheet you want it to work.
 

Attachments

  • Capture.JPG
    Capture.JPG
    103.4 KB · Views: 6
Upvote 0
Insert the provided code into the worksheet object for the worksheet you want it to work.
i did, but unfortantily how ever my the data on my sheet is interfering i think

as when i put in to a blank worksheet it works but not on my filled in sheet
 
Upvote 0
1668692829773.png
1668693139929.png

theses are the two types of sheets i want to put them on the line appear oranage when i genrate the sheet but after that doesnt move and bugs when i click another cell
 
Upvote 0
Did you adapt the code to what you need? My code works for selecting any cell in column A.
yeah i change them but tested them in a first
the problem with one of them is i think i have a private sub running for one of the sheets but the other sheet should be effected by this
 
Upvote 0
yeah i change them but tested them in a first
the problem with one of them is i think i have a private sub running for one of the sheets but the other sheet should be effected by this
Your private sub looks like is causing wrong behavior of this sub
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,795
Members
449,468
Latest member
AGreen17

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