Highlight cells in column if Column name does not include ..

gripper

Board Regular
Joined
Oct 29, 2002
Messages
176
I am struggling to get this code to verify. I am hitting a syntax issue on the line "If UCase(c.Value) Not Like "*STACKER*" Then"

I want the code to look into the column headers and if a partial string match occurs then go down the column and highlight if it meets the criteria

I want it to do this for all matches except if the partial string has the word "Stacker" in the column name.

I cannot figure out the issue.

Thank you in advance for the assistance

VBA Code:
Sub HighlightLongShort()
  Dim c As Range

  ' Loop through each cell in the first row of the active sheet
  For Each c In ActiveSheet.Range("1:1").Cells
    ' Check if the column header does not contain "Stacker" (not case sensitive)
    If UCase(c.Value) Not Like "*STACKER*" Then
      ' Check if the column header contains "Long" or "Short" (not case sensitive)
      If UCase(c.Value) Like "*LONG*" Or UCase(c.Value) Like "*SHORT*" Then
        ' Loop through each cell in the column
        For Each cell In c.EntireColumn.Cells
          ' Check if the cell value is not equal to 0
          If cell.Value <> 0 Then
            ' Highlight the cell with the desired RGB color
            cell.Interior.Color = RGB(255, 255, 0)
          End If
        Next cell
      End If
    End
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try changing the "Not Like" line to If Not UCase(c.Value) Like "*STACKER*" Then
 
Upvote 0
I am struggling to get this code to verify. I am hitting a syntax issue on the line "If UCase(c.Value) Not Like "*STACKER*" Then"

I want the code to look into the column headers and if a partial string match occurs then go down the column and highlight if it meets the criteria

I want it to do this for all matches except if the partial string has the word "Stacker" in the column name.

I cannot figure out the issue.

Thank you in advance for the assistance

VBA Code:
Sub HighlightLongShort()
  Dim c As Range

  ' Loop through each cell in the first row of the active sheet
  For Each c In ActiveSheet.Range("1:1").Cells
    ' Check if the column header does not contain "Stacker" (not case sensitive)
    If UCase(c.Value) Not Like "*STACKER*" Then
      ' Check if the column header contains "Long" or "Short" (not case sensitive)
      If UCase(c.Value) Like "*LONG*" Or UCase(c.Value) Like "*SHORT*" Then
        ' Loop through each cell in the column
        For Each cell In c.EntireColumn.Cells
          ' Check if the cell value is not equal to 0
          If cell.Value <> 0 Then
            ' Highlight the cell with the desired RGB color
            cell.Interior.Color = RGB(255, 255, 0)
          End If
        Next cell
      End If
    End
You do realize this could probably be done using Conditional Formatting regardless of what version of Excel you're using. It would be helpful if you updated your profile and indicated what OS and Excel Version you're using. Although it's not relevant here (yet?), it's also considerate to use XL2BB when posting data, but that's for another day!
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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