need help connecting the code, Dave Help!!!!

R

RompStar

Dave :- ), everyone :- )

Ok, imagine a excel sheet, has columns A to O

column Names/Headers are at A9:O9

at A10:O10 raw data...

So the user enters the dates, this time from column A,

START DATE

END DATE,

I need help to feed that collected data to the last part, see code...
can anyone help me out.. ? that part of the code works, but I have to
select with a mouse, I would rather have the user enter the date range
and then it automatically print it, because there is a lot of ROWS,
like 3000 and counting...

Sub PrintRange()

Dim LastRow As Long
Dim Rng As Range
Dim Msg As Integer
Dim BeginDate As Date
Dim EndDate As Date
Dim c As Range
Dim Item As Range
LastRow = Range("A10").End(xlDown).Row
Set Rng = Range("A10" & Range("A65536").End(xlUp).Row)

Do
Msg = vbOK
BeginDate = Application.InputBox("Enter Starting Date from
column A:", "Range Beginning", Type:=1)
If Not IsDate(BeginDate) Then

' Checks to see if entry is a date

Msg = MsgBox("Entry not a valid date!", vbCritical +
vbRetryCancel, "Error: Invalid Date")
End If
' Converts to date format
BeginDate = DateValue(BeginDate)
Loop While Msg = vbRetry

Do
Msg = vbOK
EndDate = Application.InputBox("Enter Ending Date from column
A:", "Range Ending", Type:=1)
If Not IsDate(EndDate) Then

Msg = MsgBox("Entry not a valid date!", vbCritical +
vbRetryCancel, "Error: Invalid Date")
End If
EndDate = DateValue(EndDate)

Loop While Msg = vbRetry


MsgBox "You selected: " & BeginDate & " through " & EndDate & " ", ,
"Select Range"

' Pass the selected Range to the code below, not sure how yet :- )

On Error GoTo Finish

' --------------------------

Worksheets("Master").Activate
Set myRange = Application.InputBox( _
Prompt:="Select a Range to print!" & Chr(13) & Chr(13) & "Use your
mouse!" & Chr(13) _
& "For more than one Range add a ""comma"" between your selected
Ranges!", Type:=8)
myRange.Select
MsgBox "Ready to print: " & Selection.Address
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveSheet.PageSetup.FitToPagesWide = 1
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Master").Range("A1").Select

Finish:

End Sub
 
D

Dave Peterson

How about having your macro do a filter on the data.

You can show rows that are greater than or equal to the begin date and less than
or equal to the end date.

Then just print those visible rows.

Sometimes dates are fussy when working in VBA and autofilter. You may have to
use the format of the date column in your criteria.

===
You may even just want to teach people to use Data|Autofilter (and custom).
This is one of the most powerful tools you have in your excel arsenal. And
it'll be applicable to lots and lots of other workbooks.
 

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