Changing Date

Nestes2000

New Member
Joined
Oct 23, 2018
Messages
1
Hi Guys,

I'm new with macros/VBA...

How can I create a button that ask me a date and then change the dates on a column with the date I inputed?

Many Thanks in Advance
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the message board!

Here's a little code you can adjust to suit your needs:
Code:
Sub ChangeDates()

Dim MyText As String
Dim MyDate As Date
Dim Rng As Range


'VBA doesn't crash but goes to error handler if InputBox returns a value that can't be changed to a date
On Error GoTo ErrorHandler


'Adjust the Rng to match your needs
Set Rng = Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)


'InputBox returns a string:
MyText = Application.InputBox("Enter a date")


'CDate turns strings to dates:
MyDate = CDate(MyText)


With Rng
    .Value = MyDate
End With


'If a date was entered the macro stops here:
Exit Sub


'otherwise the code jumps here:
ErrorHandler:
    MsgBox "Try again with a suitable date.", vbOKOnly, MyText & " ?"


End Sub

You can either insert a button from the Form Controls or use any shape and assign the macro to that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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