Removing forward slash from date using vba

litestream

Active Member
Joined
Jul 24, 2006
Messages
323
When I use:

If TextBox1.Value > 0 Then
TextBox2.Text = (7 * Val(TextBox1.Text)) + DateSerial(Year(Date), 1, 1) - 9
End If
End Sub

It returns a date in the format "16/7/2008" which is fine for the display in text box 2, but how can I convert this to "160708" format so that I can include it in my file name?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
in VBA format the date to your wishes

Code:
Format(CDate(Textbox2.Text),"DDMMYY")
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
Private Sub TextBox1_Change()
    If TextBox1.Value > 0 Then
        TextBox2.Text = Format((7 * Val(TextBox1.Text)) + DateSerial(Year(Date), 1, 1) - 9, "ddmmyy")
    End If
End Sub
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
Andrew, I believe OP wanted to keep slashes for TB presentation but remove for purposes of use within filename.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092

ADVERTISEMENT

Andrew, I believe OP wanted to keep slashes for TB presentation but remove for purposes of use within filename.

I agree. I read the question too quickly.
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Hi, litestream

Code:
TextBox2.Text = Replace(TextBox2.Text , "/", "")
Mick
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,983
Messages
5,834,709
Members
430,311
Latest member
JAC0617

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
Top