Highlight range of cells if one cell contains certain data

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
826
Office Version
  1. 365
Platform
  1. Windows
I was wandering if the code below could be changed in a way where if the target had G4496-9809 it would still highlight.
Also if it could highlight the entire row instead of just the one cell. Thanks Jamey


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "[COLOR=#FF0000]G4496" T[/COLOR]hen Target.Interior.ColorIndex = 3
If Target.Value = "G4222" Then Target.Interior.ColorIndex = 4
If Target.Value = "G4276" Then Target.Interior.ColorIndex = 6
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Just change G4496 to G4496-9809

and change Target.interior.colorindex to target.row.interior.colorindex
 
Upvote 0
Im getting a Compile Error: Invalid qualifier
When G4496 is entered
It highlights
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "G4496" Then Target.Row.Interior.ColorIndex = 3
If Target.Value = "G4222" Then Target.Row.Interior.ColorIndex = 4
If Target.Value = "G4276" Then Target.Row.Interior.ColorIndex = 6
End Sub
 
Upvote 0
thanks for the help. One more question. I need it where if the cell contains the value G4474 it will highlight the row. The value could be different variables such as G4474-456-5 or G4474-200 or just G4474 and so on.....

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "G4474" Then Target.EntireRow.Interior.ColorIndex = 3
If Target.Value = "G4326" Then Target.EntireRow.Interior.ColorIndex = 4
End Sub
 
Upvote 0
It works great unless I have to delete the Value. Is there something to keep it from debugging if I have to delete. ???
 
Upvote 0
Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Value = "" Then Target.EntireRow.Interior.ColorIndex = xlNone
If InStr(Target.Value, "G4474") >= 1 Then Target.EntireRow.Interior.ColorIndex = 3
If Target.Value = "G4222" Then Target.Interior.ColorIndex = 4
If Target.Value = "G4276" Then Target.Interior.ColorIndex = 6
End Sub
 
Upvote 0
ok Ive run into a problem. The data is copied from on sheet to another with a macro. So if I type G4474 in it highlights as needed If I enter it in on the sheet where the macro is and it copies , it doesnt highlight.. Can the code be edited where if the sheet Contains the desired data it will just shade on its on
 
Upvote 0

Forum statistics

Threads
1,215,555
Messages
6,125,490
Members
449,234
Latest member
slzaleski

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