Paste MsgBox Info to Cell??

T

TAlbertini

I have a MsgBox in which the user enters a start and end date to
create a report from data. Is there a way to copy the information the
user enters in the MsgBox to cells on the worksheet so it is displayed
what dates are on the report. I have put the code below, and I want
to put the start date in cell D:3 and the end date in cell D:4. I
appreciate any help anyone could offer on this...

Private Sub CommandButton1_Click()
Dim dDate1 As Date, dDate2 As Date
Dim lngdate1 As Long, lngdate2 As Long

dDate1 = Application.InputBox(Prompt:="Enter a Start Date", _
Title:="START DATE FIND", Default:=Format(Date, "dd-mmm-yy"),
Type:=1)

'Cancelled
If dDate1 = 0 Then Exit Sub

If Not IsDate(dDate1) Then
MsgBox "Invalid Start Date", vbCritical
Run "FindDateRange"
End If

GetEndDate:
dDate2 = Application.InputBox(Prompt:="Enter an End Date", _
Title:="END DATE FIND", Default:=Format(Date, "dd-mmm-yy"),
Type:=1)

'Cancelled
If dDate2 = 0 Then Exit Sub

If Not IsDate(dDate2) Then
MsgBox "Invalid End Date", vbCritical
GoTo GetEndDate
End If

lngdate1 = DateSerial(Year(dDate1), Month(dDate1), Day(dDate1))
lngdate2 = DateSerial(Year(dDate2), Month(dDate2), Day(dDate2))

ActiveSheet.AutoFilterMode = False
Range("A7:A400").AutoFilter
Range("A7:A400").AutoFilter Field:=1, Criteria1:=">=" & lngdate1,
_
Operator:=xlAnd, Criteria2:="<=" & lngdate2
End Sub
 
D

Dave Peterson

Maybe something like:

with activesheet("d3")
.numberformat = "mm/dd/yyyy"
.value = date1
end with
 
C

CLR

Private Sub CommandButton1_Click()
Dim dDate1 As Date, dDate2 As Date
Dim lngdate1 As Long, lngdate2 As Long

dDate1 = Application.InputBox(Prompt:="Enter a Start Date", _
Title:="START DATE FIND", Default:=Format(Date, "dd-mmm-yy"), Type:=1)

Range("D1").Value = dDate1

'Cancelled
If dDate1 = 0 Then Exit Sub

If Not IsDate(dDate1) Then
MsgBox "Invalid Start Date", vbCritical
Run "FindDateRange"
End If

GetEndDate:
dDate2 = Application.InputBox(Prompt:="Enter an End Date", _
Title:="END DATE FIND", Default:=Format(Date, "dd-mmm-yy"), Type:=1)

Range("D2").Value = dDate1

'Cancelled
If dDate2 = 0 Then Exit Sub

If Not IsDate(dDate2) Then
MsgBox "Invalid End Date", vbCritical
GoTo GetEndDate
End If

lngdate1 = DateSerial(Year(dDate1), Month(dDate1), Day(dDate1))
lngdate2 = DateSerial(Year(dDate2), Month(dDate2), Day(dDate2))

ActiveSheet.AutoFilterMode = False
Range("A7:A400").AutoFilter
Range("A7:A400").AutoFilter Field:=1, Criteria1:=">=" & lngdate1,
Operator:=xlAnd, Criteria2:="<=" & lngdate2
End Sub
 

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