How to Keep a leading Zero in this IF statement.

Macro_Nerd99

Board Regular
Joined
Nov 13, 2021
Messages
61
Office Version
  1. 365
Rich (BB code):
   If Len(ws1.Cells(i, 1)) > 0 Then

          ws1.Cells(i, 10) = "Call Update(""" & ws1.Cells(i, 1) & """,""" & ws1.Cells(i, 2) & """,""" & ws1.Cells(i, 3) _
          & """,""" & ws1.Cells(i, 4) & """,""" & ws1.Cells(i, 5) & """,""" & ws1.Cells(i, 6) & """,""" & ws1.Cells(i, 7) & """)"
  End If

I have Cell (i,7) formatted as a date like mm/dd/yyyy to keep the leading Zero, but then when I run this IF statement part of the macro, it doesn't keep the leading zero in cell (i,10) at the end and that's an issue. How do I fix this?
 
Last edited by a moderator:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Change this part:
VBA Code:
ws1.Cells(i, 7)
to this:
VBA Code:
Format(ws1.Cells(i, 7),"mm/dd/yyyy")
 
Upvote 0
Solution
You are welcome!

Yes, it is important to note that those references only pull back the cell values, not the formats associated with those cells.
That is why you need to apply the format in the VBA code.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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