Forum

How to create a Vis...
 
Notifications
Clear all

How to create a Visual Basic to highlight cells when the value changes

6 Posts
2 Users
0 Reactions
60 Views
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

I've created a file and I want to be able to change the cell color on the Master Order Form -worksheet when one of the users enters a new value in one of the worksheets called Blair and Jason

I found this VB on the web however I can't get it to work. I have attached my file that I'm working on.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
' Highlight the active cell
Target.Interior.ColorIndex = 8
Application.ScreenUpdating = True
End Sub

 

Thanks

 
Posted : 07/12/2020 5:46 pm
(@fluff)
Posts: 36
Eminent Member
 

How about

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim RwOffset As Long
If Target.CountLarge > 1 Then Exit Sub
Select Case Sh.CodeName
Case "Sheet3": RwOffset = 1
Case "Sheet4": RwOffset = 9
Case Else: Exit Sub
End Select
Sheet1.Range(Target.Address).Offset(RwOffset).Interior.ColorIndex = 8
End Sub

 

This needs to go in the ThisWorkbook code module

 
Posted : 07/12/2020 6:16 pm
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

Hi 

This is great. I'm wondering if it's also possible to clear the cell fill if the user decides to revert back to the original value?

Thanks for your great help

 
Posted : 08/12/2020 9:15 am
(@fluff)
Posts: 36
Eminent Member
 

To do that you would need to store all the changes that were made, along with cell references, to another sheet.

 
Posted : 08/12/2020 10:42 am
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

ok thank you

 
Posted : 09/12/2020 9:55 am
(@fluff)
Posts: 36
Eminent Member
 

You're welcome

 
Posted : 09/12/2020 2:05 pm
Share: