VBA code military time hassles... please help!

briantemp

New Member
Joined
Apr 7, 2004
Messages
19
Before I pull the rest of my hair out... :banghead:

I have a spreadsheet in which I'm entering start and end times, then applying a simple calculation to get the differance between the two. I'm using this VBA data to eliminate the need to type a colon-

Private Sub Worksheet_Change(ByVal Target As Range)
UserInput = Target.Value
If UserInput > 1 Then
NewInput = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
Application.EnableEvents = False
Target = NewInput
Application.EnableEvents = True
End If
End Sub

-and it works great EXCEPT FOR when I have a time such as 0035 in which case it displays :35 only, which prevents the calcuation from being made. I've tried several reformattings of the cells with double-zero times but nothing works. Is there a simple solution I can apply? I'm not as tech-savvy with macro/VBA applications as I wish I was, so a cut and paste option would be greatly appreciated... or at least an "in simple terms" solution.

This messageboard is brilliant with info... hopefully someone can help me out?

Thanx muchly! :pray:

~Brian
 
Change the line :-

If Not Intersect(Target, [B:C]) Is Nothing Then

To :-

If Not Intersect(Target, [B:C,F:E,O:N, ...and so on to... AG:AF]) Is Nothing Then


Above has not been tested.
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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