Conditional test not evaluating properly

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
618
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
For the life of me, I cannot figure this out. When the cell at .Cells(i, col) has the value 0\1 (as text), my conditional statement that evaluates if str = "0/1" is FALSE. Likewise, str Like "0/*" is always FALSE for values like "0\9". What am I doing wrong?

Code:
' ~~ Format START/STOP cells for better visualization
          col = tbl_Watchstop.ListColumns("Split counter").DataBodyRange.column
          For i = 1 To tbl_Watchstop.ListRows.count + 1
            str = .Cells(i, col).value
            If str = "0/1" Then .Cells(i, col).Interior.Color = 6750156  ' ~~ Light green for START
            If str Like "0/*" And str <> "0/1" Then .Cells(i, col).Interior.Color = 16764159  ' ~~ Light pink for STOP
          Next i
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
what does str give you in the immediate window

Code:
' ~~ Format START/STOP cells for better visualization
          col = tbl_Watchstop.ListColumns("Split counter").DataBodyRange.column
          For i = 1 To tbl_Watchstop.ListRows.count + 1
            str = .Cells(i, col).value
Debug.Print str
            If str = "0/1" Then .Cells(i, col).Interior.Color = 6750156  ' ~~ Light green for START
            If str Like "0/*" And str <> "0/1" Then .Cells(i, col).Interior.Color = 16764159  ' ~~ Light pink for STOP
          Next I
 
Upvote 0
For the life of me, I cannot figure this out. When the cell at .Cells(i, col) has the value 0\1 (as text), my conditional statement that evaluates if str = "0/1" is FALSE. Likewise, str Like "0/*" is always FALSE for values like "0\9". What am I doing wrong?
Comparing backslashes ("\") with forwardslashes ("/")?
 
Last edited:
Upvote 0
You've got to be kidding me!! I knew it had to be something bone-headed, but I had no idea I was THAT bone-headed!!!

Pointing out errors without being judgemental -- that's a community worth being a part of. Thanks, Tetra.
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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