View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Trying to increment by one day in a macro

Your code worked for me--after I dimmed I--and if I put valid entries in each
choice.

I'm guessing that you were typing something in that excel couldn't see as a
date.

Option Explicit
Private Sub cmdPrint_Click()
'Dim Variables
Dim D As Long
Dim I As Long

With Sheets("LogSheet")
If IsDate(Me.txtStartDate.Value) Then
.Range("Date") = CDate(Me.txtStartDate.Value)
Else
MsgBox "Please enter a date!"
Exit Sub
End If

D = 0
If IsNumeric(Me.cboNrOfDays.Value) Then
D = CLng(Me.cboNrOfDays.Value)
End If
If D = 0 Then
MsgBox "Please enter the number of days"
Exit Sub
End If

'Print Selected Number of Days
For I = 1 To D
.PrintOut preview:=True, Copies:=1, Collate:=True
.Range("Date").Value = .Range("Date").Value + 1
Next I
End With
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.cboNrOfDays
.Clear
For iCtr = 1 To 5
.AddItem iCtr
Next iCtr
End With
End Sub

(I added the preview:=true to save some trees while testing.)



PhilB wrote:

Hello,
Having all sorts of fun getting this one worked out, to date, no
success at all
I basically one to have a form to collect the start date and nr of days
required then print the worksheet with the dates incrementing from the
start date by one for the number of days required.
This is what I have tried:

Private Sub cmdPrint_Click()
'Dim Variables
Dim D As Integer
Sheets("LogSheet").Select
Range("Date") = ""
'Transfer Info from frmDriverLogInfo
Sheets("LogSheet").Select
Range("Date") = txtStartDate.Value
D = cboNrOfDays.Value
'Print Selected Number of Days
For I = 1 To D
Sheets("LogSheet").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveSheet.Range("Date").Value = ActiveSheet.Range("Date").Value +
1
Next I
End Sub

Any help would be most appreciated.
Many thanks, Phil

--
PhilB
------------------------------------------------------------------------
PhilB's Profile: http://www.excelforum.com/member.php...o&userid=12866
View this thread: http://www.excelforum.com/showthread...hreadid=318973


--

Dave Peterson