LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Trying to increment by one day in a macro

Getting a date from a Textbox or inputbox can be a problem.

You may want to consider adding a calendar control to your form. (It'll look
pretty neat, too!)

Ron de Bruin has some samples at:
http://www.rondebruin.nl/calendar.htm

Ron has a link (at the bottom of that URL) where you can get a free version of a
control. (It's not included in excel (but if you have it, you can use it
there.) (I think it's installed with Access.)



PhilB wrote:

Dave,
This is what I ended up, borrowing the code you supplied and
transferring the 'date' range to another worksheet. I guessed that it
may have been an issue with formatting the date on the printed sheet
that was causing the problem as I was trying to seperate d/mmm/yyyy
into three seperate cells to prevent the ### problem in columns that
were fitting the other information.

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

With Sheets("DataSheet")
If IsDate(Me.txtStartDate.Value) Then
Sheets("DataSheet").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
'Unload Form
Unload frmDriverLogInfo
'Print Selected Number of Days
For I = 1 To D
'Change PrintOut to PrintOut preview = true for testing
Sheets("LogSheet").PrintOut Copies:=1, Collate:=True
Sheets("DataSheet").Range("date").Value =
Sheets("DataSheet").Range("date").Value + 1
Next I
End With
Sheets("DataSheet").Range("date").Value =
Sheets("DataSheet").Range("date").Value - 1
For Each w In Application.Workbooks
w.Save
Next w
Application.Quit
End Sub

Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.cboNrOfDays
Clear
For iCtr = 1 To 7
AddItem iCtr
Next iCtr
End With
End Sub

I tacked the -1 day on the end to save it at the last day printed.
Many thanks for all your help, it certainly made the problem less
problematic.
Take care, 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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro - How to increment cell reference by one row lau_ash[_2_] Excel Worksheet Functions 7 April 4th 23 02:17 PM
Using macro recorder increment cell by one? Student2 Excel Discussion (Misc queries) 4 March 26th 09 05:05 PM
copy cell with macro and increment down each time RJJ Excel Worksheet Functions 6 May 9th 08 06:16 PM
Macro to increment invoice number Paul Excel Programming 1 September 19th 03 08:58 PM
Macro to Increment a Cell's Value By 1 Dave[_25_] Excel Programming 2 August 10th 03 09:33 PM


All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"