Check to Table columns for Criteria VBA

Skybluekid

Well-known Member
Joined
Apr 17, 2012
Messages
1,226
Office Version
  1. 365
Platform
  1. Windows
Hi

I have two columns in a table, Column V and Column W. I would like to check the cells in the row of each column to see if the conditional formatting is Red. If so, then bring back the row number.

I am using the ListColumns to get the Header name as the table will expand over time.

Thanks in Advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
For example:

VBA Code:
Sub jec()
 Dim it, a
 For Each it In Range("V:W").SpecialCells(2)
   If it.DisplayFormat.Interior.Color = vbRed Then a = a & it.Row & vbLf
 Next
 MsgBox "Rows:" & vbLf & a
End Sub
 
Last edited:
Upvote 0
Thanks @JEC ,

Sorry didn't make myself clear. In my table, I would like to reference the Column names, which I have called "Col V' and "Col W", in the Header Row. This is because the table will expand in the future.
 
Upvote 0
Ok, this is how you refer to Listobject columns.

VBA Code:
Sub jec()
 Dim it, a
 With Sheets(1).ListObjects(1)
   For Each it In Union(.ListColumns("COL V").Range, .ListColumns("COL W").Range)
     If it.DisplayFormat.Interior.Color = vbRed Then a = a & it.Row - .HeaderRowRange.Row & vbLf
   Next
   MsgBox "ListObjectRows:" & vbLf & a
 End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,073
Messages
6,122,974
Members
449,095
Latest member
Mr Hughes

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