Macro

C

Cedric

I recently found the macro listed below. If I wanted the macro to run until
I enter XXX how would I go about that. I would want a line between each date.


Option Explicit

Private Sub Workbook_Open()

Dim vDate As String

vDate = InputBox("Please type in a date")

Worksheets("Sheet1").Range("A1") = vDate

End Sub


Thanks in advance
 
D

Dave Peterson

Option Explicit
Private Sub Workbook_Open()

Dim vDate As String
Dim DestCell As Range

Set DestCell = Worksheets("Sheet1").Range("A1")

Do
vDate = InputBox("Please type in a date")
If LCase(vDate) = LCase("xxx") Then
Exit Do
Else
DestCell = vDate
Set DestCell = DestCell.Offset(2, 0)
End If
Loop

End Sub
 
G

Gord Dibben

The macro would drop dates in column A so fast you would be full before you ever
typed your XXX

How about two inputboxes?

One for the date and one for the number of dates down column A

Private Sub Workbook_Open()
Dim rng As Range
Dim I As Integer
Dim vDate As Date
Dim numtimes As Integer
With Sheets("Sheet1")
vDate = InputBox("Please type in a date")
numtimes = InputBox("How far to increment? Enter a number")
Set rng = Range("A1")
rng.Value = vDate
For I = 1 To numtimes Step 1
rng.Offset(I, 0).Value = rng.Offset(I - 1, 0).Value + 1
Next I
End With
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top