VBA if criteria statement help

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
864
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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Trying2learnVBA

Board Regular
Joined
Aug 21, 2019
Messages
67
Office Version
  1. 365
  2. 2021
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
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.
 

Forum statistics

Threads
1,182,107
Messages
5,933,698
Members
436,905
Latest member
Ibraeh

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
Top