Need help to increment date column with macro (repost)

dwest100

Board Regular
Joined
Jan 2, 2005
Messages
138
I have a column of dates (column d). New dates are added and deleted regularly.

I need to be able to increment all the dates in the column by a specific number of days, forward or backward, using a macro.

The macro needs to pop open a dialog window to prompt me for the number of days I wish to increment the dates in the column, and also whether to index forward or backward depending on which radio button is selected (forward or backward). Default would be forward.

How can I do this?

Any help would be greatly appreciated!
 
I'm also running this macro off of the menu OnAction:

Sub ShowForm()
frmAdjustSchedule.Show
End Sub

Could that be the cause?
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi psitaram,
I did that and I get the same result.

Any ideas?

Private Sub CommandButton1_Click()
Dim DateCell As Range
If frmAdjustSchedule.OptionButton1.Value = False And frmAdjustSchedule.OptionButton2.Value = False Then
MsgBox "Please select forward or backward."
Exit Sub
ElseIf Not IsNumeric(frmAdjustSchedule.TextBox1.Value) Then
MsgBox "Please enter the number of days to adjust the schedule."
Exit Sub
End If

myIncr = Int(frmAdjustSchedule.TextBox1.Value)

If frmAdjustSchedule.OptionButton1.Value = True Then
For Each DateCell In Sheets(1).Range("d4:d" & Sheets(1).[d65536].End(xlUp).Row)

DateCell = DateCell + myIncr
Next DateCell

ElseIf frmAdjustSchedule.OptionButton2.Value = True Then
For Each DateCell In Sheets(1).Range("d4:d" & Sheets(1).[d65536].End(xlUp).Row)

DateCell = DateCell - myIncr
Next DateCell
End If
Unload frmAdjustSchedule
End Sub

Private Sub CommandButton2_Click()
Unload frmAdjustSchedule
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,840
Members
449,193
Latest member
MikeVol

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