VBA if criteria statement help

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All,

In working in the range E11:E180; how do I add an IF statement criteria to an already existing vba code below?

Whereby, IF cell E11 has an interior color red to then return that interior cell color?

I would like to add this criteria to an existing code, where it will not remove the interior cell color red for example E11 after that sub is completed.

So basically....

range E11:E180

IF cells of range has an interior color red to then return that cell of E11's interior cell back to red.


Here is a sample of the code:

VBA Code:
Sub Test()

Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "H").End(xlUp).row
    For i = 1 To Lastrow
        If Cells(i, "H").Interior.Color = vbRed Then Cells(i, "H").Value = "Enter Tally"
    Next
  

End Sub



This code is interrupting my Column E interior cell color and I do not want it to.

Please let me know, if you can help!

Thanks you!
pinaceous
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi All,

In working in the range E11:E180; how do I add an IF statement criteria to an already existing vba code below?

Whereby, IF cell E11 has an interior color red to then return that interior cell color?

I would like to add this criteria to an existing code, where it will not remove the interior cell color red for example E11 after that sub is completed.

So basically....

range E11:E180

IF cells of range has an interior color red to then return that cell of E11's interior cell back to red.


Here is a sample of the code:

VBA Code:
Sub Test()

Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "H").End(xlUp).row
    For i = 1 To Lastrow
        If Cells(i, "H").Interior.Color = vbRed Then Cells(i, "H").Value = "Enter Tally"
    Next
 

End Sub



This code is interrupting my Column E interior cell color and I do not want it to.

Please let me know, if you can help!

Thanks you!
pinaceous
Are you using conditional formatting to make the cells red? If so, I would think once the value becomes "Enter Tally" this alters your conditional formatting.
I tried your code and it worked but I manually highlighted the cells red not with conditional formatting. The cells stayed color red.
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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