Is it possible to make a script or function in Excel to transform entered time data?

Mogster

New Member
Joined
Aug 20, 2022
Messages
1
Office Version
  1. 2019
  2. 2013
  3. 2010
Platform
  1. Windows
  2. Web
Hello everyone,

I am dealing with a large group of users who are used to entering time data as mm:ss or h:mm:ss, but seem to be struggling to enter a zero for the hour when the value is under 1 hour. Is it possible to make a script transform the entered data based on its length to the proper values?

ie. if the length of the data entered in the cell is 4 or 5 characters long, examples: 1:23, 13:50 it would transform these entered values to be stored as mm:ss not hh:mm?

If the data length is 7 or 8, it would treat it properly as h:mm:ss. (1:44:50)

If anyone has any suggestions or could guide me in the right direction, it's much appreciated. Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You will need to change some of this but here is what I have so far. If you could send either a picture or excel file of that would help a lot on understanding where the information is coming from and where you want the code to throw the new data. I'm going to paste what I have so far just in case you are familiar with VBA.
VBA Code:
Public Sub correction()
Dim word As String: word = ActiveCell.Text
Dim length As Integer: length = Len(word)

If length = 4 Then

ActiveCell.Offset(0, 1).Value = Format("0:" & Left(word, 1) & ":" & Mid(word, 3, 2), "hh:mm:ss")

ElseIf length = 5 Then

ActiveCell.Offset(0, 1).Value = Format("0:" & Left(word, 2) & ":" & Mid(word, 4, 2), "hh:mm:ss")

Else

ActiveCell.Offset(0, 1).Value = Format(word, "hh:mm:ss")


End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

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