VBA Time change

Status
Not open for further replies.

BOGIA

Active Member
Joined
May 23, 2005
Messages
266
Hi everyone,

I'm trying to write a short statement to change the time if it is greater than 6:00:00 but it doesn't work. The data I have always 6:00:10 or more.

I have tried this but no good:

If range("a1","a4:a6","a7","a10:a15") > 6:00:00 then
range("a1","a4:a6","a7","a10:a15") = 6:00:00
End if

Could anyone please help! Thanks

TD
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Derek

Well-known Member
Joined
Feb 16, 2002
Messages
1,592
Hi there

Try this in a standard module:

Sub ResetTime()
For Each cell In Range("a1, a4:a6, a7, a10:a15")
If cell.Value > TimeValue("6:00:00") Then cell.Value = TimeValue("6:00:00")
Next
End Sub


regards
Derek

PS Didn't realise you had 2 threads going with the same question. Best to stick to the original thread or it gets confusing for everyone.
 
Status
Not open for further replies.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,995
Messages
5,834,779
Members
430,321
Latest member
yemisimi11

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