Conditional test not evaluating properly

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
609
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
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

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
609
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
bump
 
Upvote 0

Tetra201

MrExcel MVP
Joined
Oct 14, 2016
Messages
3,801
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

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
609
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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,191,219
Messages
5,985,330
Members
439,958
Latest member
qb0000

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