Like operator

ccordner

Active Member
Joined
Apr 28, 2010
Messages
355
I have a series of cells, all displaying times, some of which are formatted to display in the 24 hour clock ("##:##") and some of which are formatted to appear as "##h##". This is to differentiate between actual times of the day and lengths of shifts.

Is there an easy way of using vba to work out which is which?

I had been using "if .... like "#h#" but that doesn't work, because it's only the format of the cell, not the actual number.

Any ideas?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
..and some of which are formatted to appear as "##h##". This is to differentiate between actual times of the day and lengths of shifts...

So "##h##" still refers to a valid time in the formula bar? If I got that correct, you may want to try Cell.Text rather than .Value.
 
Upvote 0
Thanks, that's kind of working.

The cell I'm referring to contains a reference to another worksheet. Well, in some cases. Sometimes it contains an actual value but this needs to be able to work with either.

I've put in a msgbox(cells(rownumber+3,3).text) and that displays "4h00".

Yet for some reason, neither the statements 'like "#h#"' nor 'like "#[h]#"' seem to work?
 
Upvote 0
..Yet for some reason, neither the statements 'like "#h#"' nor 'like "#[h]#"' seem to work?

'#h#' would match '4h0' but not '4h00' when used in Like. The '#' matches exactly one digit, not one-to-many.

Could you show some sample data variations?
 
Upvote 0
Certainly, although you've just given me the answer.

The shifts would never be more than 12 hours, so something like 4h00, 8h45, 12h00 are the kind of results.

Therefore, like "#h##" or "##h##" should do the trick.

Chris.
 
Upvote 0
Super cool, its always nice when it works out quick:grin:
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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