How to fill selected cells with given data?

October 2016


I often need to fill cells with a date of production.
What kind of a macro would be useful in this situation so that I could just select the cells that I need to fill and just enter the date of productions?


Here is a macro. Give it a shot, but make sure that you have a backup before hand. Select the target cells first and run the macro
If you press cancel, it would wipe out all the data of selection. Not a good idea.

Use this. It will confirm before wiping out:

Sub fixDate()
    Dim vValue As Variant
    'default date is yesterday
    vValue = InputBox("Enter Date", "Date", Date - 1)
    If (vValue = "") Then
        confirm = MsgBox("Do you wish to wipe out data from selection ?", vbQuestion + vbYesNo)
        If confirm <> vbYes Then Exit Sub
    End If
    For Each cell In Selection
        cell.Value = vValue
End Sub


Thanks to rizvisa1 for this tip on the forum.

Related :

This document entitled « How to fill selected cells with given data? » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.