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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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