VBA Select Case or If question

Pinaceous

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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Max1616

Well-known Member
Joined
Nov 25, 2015
Messages
515
Office Version
  1. 2016
Platform
  1. Windows
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
 

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
864
Office Version
  1. 365
Platform
  1. Windows
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
 

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
864
Office Version
  1. 365
Platform
  1. Windows
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!
 

johnnyL

Well-known Member
Joined
Nov 7, 2011
Messages
3,958
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
8 & 9 are the column #s. abcdefg H I jklmn, etc
 

Forum statistics

Threads
1,181,212
Messages
5,928,724
Members
436,625
Latest member
agholson81

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