Devin
Board Regular
- Joined
- Jan 21, 2009
- Messages
- 105
I need to convert these funky time formats into a time format that excel will recognize. Additionally, not all the cells this formula points to are times so it must return "". I managed to get the job done with the UDFs and formula shown below. Does anyone have a better idea?
UDFs:
Function HourFormat(ByRef Hf As Range)
HourFormat = Evaluate("IF(LEN(" & Hf.Address & ")>4,LEFT(" & Hf.Address & ",2),LEFT(" & Hf.Address & ",1))")
End Function
Function MinFormat(ByRef Mf As Range)
MinFormat = Evaluate(Mid(Right(Mf, 3), 1, 2))
End Function
Formula:
=IF(OR(RIGHT(A2)="a",RIGHT(A2)="p"),TRIM(IF(ISERROR(Hourformat(A2)+MinFormat(A2)),"",Hourformat(A2)&":"&IF(MinFormat(A2)<10,"0"&MinFormat(A2),MinFormat(A2))&IF(RIGHT(A2)="a"," AM"," PM"))),"")
Sheet1
<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD></TD><TD>A</TD><TD>B</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>1000a</TD><TD style="TEXT-ALIGN: right">10:00 AM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD>1100a</TD><TD style="TEXT-ALIGN: right">11:00 AM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD>1200p</TD><TD style="TEXT-ALIGN: right">12:00 PM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD>100p</TD><TD style="TEXT-ALIGN: right">1:00 PM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD>200p</TD><TD style="TEXT-ALIGN: right">2:00 PM</TD></TR></TBODY></TABLE>
<TABLE style="FONT-SIZE: 10pt; BORDER-LEFT-COLOR: #00ff00; BORDER-BOTTOM-COLOR: #00ff00; COLOR: #000000; BORDER-TOP-STYLE: groove; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-RIGHT-STYLE: groove; BORDER-LEFT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-RIGHT-COLOR: #00ff00; BORDER-BOTTOM-STYLE: groove"><TBODY><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-SIZE: 9pt; FONT-FAMILY: Arial" cellSpacing=0 cellPadding=2 border=1><TBODY><TR style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #cacaca"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>B1</TD><TD>=IF(OR(RIGHT(A1,1)="a",RIGHT(A1,1)="p"),TRIM(IF(ISERROR(Hourformat(A1)+MinFormat(A1)),"",Hourformat(A1)&":"&IF(MinFormat(A1)<10,"0"&MinFormat(A1),MinFormat(A1))&IF(RIGHT(A1)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B2</TD><TD>=IF(OR(RIGHT(A2)="a",RIGHT(A2)="p"),TRIM(IF(ISERROR(Hourformat(A2)+MinFormat(A2)),"",Hourformat(A2)&":"&IF(MinFormat(A2)<10,"0"&MinFormat(A2),MinFormat(A2))&IF(RIGHT(A2)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B3</TD><TD>=IF(OR(RIGHT(A3)="a",RIGHT(A3)="p"),TRIM(IF(ISERROR(Hourformat(A3)+MinFormat(A3)),"",Hourformat(A3)&":"&IF(MinFormat(A3)<10,"0"&MinFormat(A3),MinFormat(A3))&IF(RIGHT(A3)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B4</TD><TD>=IF(OR(RIGHT(A4)="a",RIGHT(A4)="p"),TRIM(IF(ISERROR(Hourformat(A4)+MinFormat(A4)),"",Hourformat(A4)&":"&IF(MinFormat(A4)<10,"0"&MinFormat(A4),MinFormat(A4))&IF(RIGHT(A4)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B5</TD><TD>=IF(OR(RIGHT(A5)="a",RIGHT(A5)="p"),TRIM(IF(ISERROR(Hourformat(A5)+MinFormat(A5)),"",Hourformat(A5)&":"&IF(MinFormat(A5)<10,"0"&MinFormat(A5),MinFormat(A5))&IF(RIGHT(A5)="a"," AM"," PM"))),"")</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4
UDFs:
Function HourFormat(ByRef Hf As Range)
HourFormat = Evaluate("IF(LEN(" & Hf.Address & ")>4,LEFT(" & Hf.Address & ",2),LEFT(" & Hf.Address & ",1))")
End Function
Function MinFormat(ByRef Mf As Range)
MinFormat = Evaluate(Mid(Right(Mf, 3), 1, 2))
End Function
Formula:
=IF(OR(RIGHT(A2)="a",RIGHT(A2)="p"),TRIM(IF(ISERROR(Hourformat(A2)+MinFormat(A2)),"",Hourformat(A2)&":"&IF(MinFormat(A2)<10,"0"&MinFormat(A2),MinFormat(A2))&IF(RIGHT(A2)="a"," AM"," PM"))),"")
Sheet1
<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD></TD><TD>A</TD><TD>B</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>1000a</TD><TD style="TEXT-ALIGN: right">10:00 AM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD>1100a</TD><TD style="TEXT-ALIGN: right">11:00 AM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD>1200p</TD><TD style="TEXT-ALIGN: right">12:00 PM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD>100p</TD><TD style="TEXT-ALIGN: right">1:00 PM</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD>200p</TD><TD style="TEXT-ALIGN: right">2:00 PM</TD></TR></TBODY></TABLE>
<TABLE style="FONT-SIZE: 10pt; BORDER-LEFT-COLOR: #00ff00; BORDER-BOTTOM-COLOR: #00ff00; COLOR: #000000; BORDER-TOP-STYLE: groove; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-RIGHT-STYLE: groove; BORDER-LEFT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-RIGHT-COLOR: #00ff00; BORDER-BOTTOM-STYLE: groove"><TBODY><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-SIZE: 9pt; FONT-FAMILY: Arial" cellSpacing=0 cellPadding=2 border=1><TBODY><TR style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #cacaca"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>B1</TD><TD>=IF(OR(RIGHT(A1,1)="a",RIGHT(A1,1)="p"),TRIM(IF(ISERROR(Hourformat(A1)+MinFormat(A1)),"",Hourformat(A1)&":"&IF(MinFormat(A1)<10,"0"&MinFormat(A1),MinFormat(A1))&IF(RIGHT(A1)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B2</TD><TD>=IF(OR(RIGHT(A2)="a",RIGHT(A2)="p"),TRIM(IF(ISERROR(Hourformat(A2)+MinFormat(A2)),"",Hourformat(A2)&":"&IF(MinFormat(A2)<10,"0"&MinFormat(A2),MinFormat(A2))&IF(RIGHT(A2)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B3</TD><TD>=IF(OR(RIGHT(A3)="a",RIGHT(A3)="p"),TRIM(IF(ISERROR(Hourformat(A3)+MinFormat(A3)),"",Hourformat(A3)&":"&IF(MinFormat(A3)<10,"0"&MinFormat(A3),MinFormat(A3))&IF(RIGHT(A3)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B4</TD><TD>=IF(OR(RIGHT(A4)="a",RIGHT(A4)="p"),TRIM(IF(ISERROR(Hourformat(A4)+MinFormat(A4)),"",Hourformat(A4)&":"&IF(MinFormat(A4)<10,"0"&MinFormat(A4),MinFormat(A4))&IF(RIGHT(A4)="a"," AM"," PM"))),"")</TD></TR><TR><TD>B5</TD><TD>=IF(OR(RIGHT(A5)="a",RIGHT(A5)="p"),TRIM(IF(ISERROR(Hourformat(A5)+MinFormat(A5)),"",Hourformat(A5)&":"&IF(MinFormat(A5)<10,"0"&MinFormat(A5),MinFormat(A5))&IF(RIGHT(A5)="a"," AM"," PM"))),"")</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4