change colour of whole row dependant on cell value

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi good morning, hope you can help. I have the code below where if OOH is in a cell I want the whole row to change colour, but the code below is not working, hope you can help?

Code:
Private Sub Highlight()
Dim col As Range
Dim value(0) As Integer
Worksheets("Sheet1").Activate
Set col = Range("H5:h")
If col.value = OOH Then
ActiveSheet.Row.Select
With Selection.Interior
.Color = -19125255
.Font.Bold = True
        End With
                    End If
    End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Re: change colur of whole row dependant on cell value help

Hello,

Could you explain in plain English what you actually are looking for ...

Seems to me you could Filter your sheet ...
select the value OOH in Column H ...
and highlight the resulting Visible rows ...

Have a go ... and confirm ...

Is that your line of thought ...?
 
Upvote 0
Re: change colur of whole row dependant on cell value help

Hello, I didn't want to filter, I have a userform that is filled out and the info goes into sheet1, but if 'OOH' is selected and inputted in cell H want the whole row to change colour.
 
Upvote 0
Re: change colur of whole row dependant on cell value help

Try this but I would suggest if you do the entire row you are adding a lot of memory to the workbook and if you print all unused cells will look to be printed as well

Sub ChangeColor1A()
Worksheets("Sheet1").Activate
lRow = Range("H" & Rows.Count).End(xlUp).Row
Set Ran = Range("H2:H" & lRow)
For Each cell In Ran
If cell.Value = "OOH" Then cell.EntireRow.Interior.Color = -19125255
cell.Font.Bold = True
Next
End Sub
 
Upvote 0
Re: change colur of whole row dependant on cell value help

hi thank you for that code an advise. on that is it possible for the rows a-r to change colour instead of the whole lot.
 
Upvote 0
Re: change colur of whole row dependant on cell value help

Thank you again I just tried the updated code but it didn't change the colour of the row, hope you can advise please
 
Upvote 0
Re: change colur of whole row dependant on cell value help

Hello, I didn't want to filter, I have a userform that is filled out and the info goes into sheet1, but if 'OOH' is selected and inputted in cell H want the whole row to change colour.

Understand your remark ...

But in this case ... Why would you use a Loop ...?

Since you only need to highlight the current row ... :wink:
 
Upvote 0
Re: change colur of whole row dependant on cell value help

sorry I don't understand what you mean?
 
Upvote 0
Re: change colur of whole row dependant on cell value help

Hello again,

Specifically ... in your UserForm 3 ... when you are posting your data back to your worksheet with the CommandButton 3 ...

You could insert one single line to achieve your objective ...

Code:
  ' Highlight ...
If TextBox8.Value = "OOH" Then Range(.Cells(emptyRow, 1), .Cells(emptyRow, 12)).Interior.Color = -19125255

Hope this clarifies
 
Upvote 0
Re: change colur of whole row dependant on cell value help

hi i have put the code in my combobox6 but it comes up with an error, have a put this in right its highlighting .cells as an error
Code:
Private Sub ComboBox6_Change()
If ComboBox6.value = "OOH" Then Range(.Cells(emptyRow, 1), .Cells(emptyRow, 12)).Interior.Color = -19125255
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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