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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,215,514
Messages
6,125,273
Members
449,220
Latest member
Excel Master

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