Time format isn't correct when I run VBA.

Joined
Jul 23, 2010
Messages
21
Hello:)

I have the following problem in my schedule, I can not format the correct time to 12:00 pm instead of 12:00 it appears 00:00 (midnight), even if is formated to "[h]:00".

Best regards
FS

Code:
Me.TextBox8.Text = .Cells(2, 3).Value
Me.TextBox8.Text = Format(TextBox8.Value, "[hh]:mm")
horario002.png
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I don't think so; it may be 12, but not 12:00. What's it show when you format it as General?

Also,
Code:
Me.Textbox8.Value = Format(.Range("C2").Value2, "[hh]:mm")
 
Last edited:
Upvote 0
Hi,

By testing the formats, this appears normal and the result appeared OK.

Code:
Sub test()
Range("A1").Value = Range("A2").Value
Range("A1").Value = Format(Range("A1").Value, "hh:mm")
End Sub

where A2's value is "12:00"

Please try rewriting your code.. maybe there's something wrong with the value of your Cell(2,3).

:)

-e.rgabrieldoronila
 
Upvote 0
I think C2 has a text value, not a time. That's why I asked what it looks like if you format it as General.
 
Upvote 0
FRANCISCO,

Same problem here. I test this code:

Code:
Private Sub CommandButton1_Click()
        Me.TextBox1.Text = ActiveSheet.Cells(1, 1).Value
        Me.TextBox1.Text = Format(Me.TextBox1.Value, "hh:mm")
        Me.TextBox2.Text = ActiveSheet.Cells(1, 2).Value
        Me.TextBox2.Text = Format(Me.TextBox2.Value, "hh:mm")
        Me.TextBox3.Text = ActiveSheet.Cells(1, 3).Value
        Me.TextBox3.Text = Format(Me.TextBox3.Value, "hh:mm")
End Sub

Result of the textbox in the form 00:00, 23:00 and 00:00

And this:
Code:
Private Sub CommandButton2_Click()
        Me.TextBox1.Text = ActiveSheet.Cells(1, 1).Value
        Me.TextBox1.Text = Format(Me.TextBox1.Value, "hh:mm AM/PM")
        Me.TextBox2.Text = ActiveSheet.Cells(1, 2).Value
        Me.TextBox2.Text = Format(Me.TextBox2.Value, "hh:mm AM/PM")
        Me.TextBox3.Text = ActiveSheet.Cells(1, 3).Value
        Me.TextBox3.Text = Format(Me.TextBox3.Value, "hh:mm AM/PM")
End Sub


Result of the textbox in the form 12:00 AM, 11:00 PM and 12:00 AM

<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL><COL><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>A</TH><TH>B</TH><TH>C</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">1</TD><TD style="TEXT-ALIGN: right">12:00:00</TD><TD style="TEXT-ALIGN: right">23:00:00</TD><TD style="TEXT-ALIGN: right">00:00:00</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">2</TD><TD style="TEXT-ALIGN: right">0,5</TD><TD style="TEXT-ALIGN: right">0,95833333</TD><TD style="TEXT-ALIGN: right">1</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">3</TD><TD style="TEXT-ALIGN: right">12:00:00 PM</TD><TD style="TEXT-ALIGN: right">11:00:00 PM</TD><TD style="TEXT-ALIGN: right">12:00:00 AM</TD></TR></TBODY></TABLE>

Markmzz
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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