VBA If And Or query on strings containing times

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

I have a range containing a series of values in hh:mm:ss format.

If any of these durations exceed 10 minutes (the "10" being contained in a worksheet range ThresholdMinutes), I need to extract the minute section of the string and add it to a string variable MyString - this is no problem.

The issue I have is how to define the logic. It needs to be:

IF the minute portion of the string exceeds the value in ThresholdMinutes
OR
IF the minute portion of the value equals ThresholdMinutes AND the second portion of the value is greater then zero

I have the following:
If Mid(MyCell, 4, 2) > ThresholdMinutes Or Mid(MyCell, 4, 2) = ThresholdMinutes And Mid(MyCell, 7, 2) > 0)) Then
MyString= MyString ", " & Mid MyCell(4,2)
End If

but it doesn't work - the first line is highlighted red, due to my poor IF AND logic - can anyone help out, please?

Thanks in advance

Pete
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Sorry, didn't mean to offend (said it with a smilie face & as a tip for the future). :)
 
Upvote 0
Peter - absolutely NO offence taken, my friend. I was more annoyed with myself for making an elementary mistake! Thanks for your help with my post and apologies for taking so long to come back to you :-)
 
Upvote 0
Peter - absolutely NO offence taken, my friend. I was more annoyed with myself for making an elementary mistake! Thanks for your help with my post and apologies for taking so long to come back to you :-)
Cheers. :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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