formatting - How can I format an hhmmAM/PM OR hmmAM/PM (no space) to time hh:mm AM/PM in excel? -
i'm working on way make enter timesheets payroll. want time entered in format hhmmam/pm, no spaces or colons , preferable typing a/p instead of am/pm , have convert standard time format colons , spaces.
i searched community , found answer gets me of way there. issue code requires use of "0" when entering hours example "0545p" converts "5:45 pm" "545p" converts "54:5 pm"
i want able enter 0545p or 545p , still 5:45 pm
here code using:
private sub worksheet_change(byval target range) if intersect(target, range("a:a")) nothing exit sub application.enableevents = false s = target.text if right(s, 1) = "a" or right(s, 1) = "a" s2 = " am" else s2 = " pm" end if target.value = left(s, 2) & ":" & mid(s, 3, 2) & s2 application.enableevents = true
end sub
source question: how can format hhmmam/pm (no space) time hh:mm am/pm in excel?
thank time.
here answer... hope help...
private sub worksheet_change(byval target range) if intersect(target, range("a:a")) nothing exit sub 'remarks: 'if want use column code change 'range("a:a") desire column 'if want imput column g 'range("g:g") , new resulting line of code 'if intersect(target, range("g:g")) nothing exit sub application.enableevents = false s = target.text if right(s, 1) = "a" or right(s, 1) = "a" s2 = " am" else s2 = " pm" end if if left(s, 2) = "11" or left(s, 2) = "12" or left(s, 2) = "10" target.value = left(s, 2) & ":" & mid(s, 3, 2) & s2 end if if left(s, 1) = "0" target.value = left(s, 2) & ":" & mid(s, 3, 2) & s2 end if if len(s) = 4 target.value = left(s, 1) & ":" & mid(s, 2, 2) & s2 end if 'the minutes inside input (545p | 0545p | 500p) 'always need 2 digits otherwise return 'other hour or smonthing 54:5 pm then... formta input is: 'hmma/p 'hhmma/p 'if want use 24h format need implementation application.enableevents = true end sub
tell me if need more.
Comments
Post a Comment