VBA Select Case or If question

Pinaceous

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

Condition, column H has an interior color of red and has the text "Enter Text" written into it and where the cell next to it in column I is blank to run a message box stating "Column H has a value and Column I does not".

Would I either write a Select case for this condition or an IF statement to run a message box for it?

For example, if I have cell H27 where its interior cell color is red and has its text of "Enter Text" in it and its corresponding cell of column I is I27 is blank it will run the message box.

If in using a select case or an IF statement, how would I code this?

I tried experimenting with
VBA Code:
Select Case Sheet1.Range("H:H").Interior.Color

But I need to add an additional criterial being that it has a value in this cell and runs the message box only when its corresponding cell of column I is blank.

Please let me know.

Thank you!
pinaceous
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I would use an if statement. Something like this:
VBA Code:
Sub Text_Check()

Dim i As Long
Dim lrow As Long

lrow = Cells(Rows.Count, 8).End(xlUp).Row 'Determines last row where data is populated in column H

For i = 2 To lrow 'Loops through rows 2 to the last row in column H
    If Cells(i, 8).Interior.Color = 255 And Cells(i, 8) = "Enter Text" And Cells(i, 9) = "" Then 'If cell Hi is red and has "Enter Text" and Cell Ii is blank, then fire the msgbox
    
        MsgBox "Missing Text in Cell H" & i
    
    End If

Next i


End Sub
 
Upvote 0
I would use an if statement. Something like this:
VBA Code:
Sub Text_Check()

Dim i As Long
Dim lrow As Long

lrow = Cells(Rows.Count, 8).End(xlUp).Row 'Determines last row where data is populated in column H

For i = 2 To lrow 'Loops through rows 2 to the last row in column H
    If Cells(i, 8).Interior.Color = 255 And Cells(i, 8) = "Enter Text" And Cells(i, 9) = "" Then 'If cell Hi is red and has "Enter Text" and Cell Ii is blank, then fire the msgbox
  
        MsgBox "Missing Text in Cell H" & i
  
    End If

Next i


End Sub
Many thanks Max1616!

That hit the spot!

BTW, can you please explain how it works?

Thanks again!
pinaceous
 
Upvote 0
Yeah, I was just wondering about the 8 and 9 but its all good I see his notes and was able to figure it out. Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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