small error in vb code (autofilter/print) - guru needed

fenster

Board Regular
Joined
Nov 11, 2002
Messages
98
could any of u guru's please have a look at this code and tell me whats wrong..

the command button is on sheet 3 where cells D4 and G4 have from / to dates. i.e d4 = 01/03/03 g4 = 31/03/03


sheet one is called voucher -column 1 is a date column.

the code should goto sheet 1,highlight column1 filter it and print.


Private Sub CommandButton1_Click()

Dim StartDate As Date
Dim EndDate As Date

Range("D4").Value = "startdate"
Range("G4").Value = "enddate"

Sheets("Voucher").Select
Columns("A:A").Select
Range("A7:A2100").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=">=startdate", Operator:=xlAnd _
, Criteria2:="<=enddate"
Selection.PrintOut Copies:=1, Collate:=True

End Sub
 
fixed the d4 , g4 values by forcing sheet4

StartDate = Format(Sheet4.Cells.Range("D4").Value, "dd/mm/yyyy")
EndDate = Format(Sheet4.Cells.Range("G4").Value, "dd/mm/yyyy")

but still the dates are swapping on me - tried regional settings but all set to europe with correct date format - ill keep looking!
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,221,711
Messages
6,161,450
Members
451,707
Latest member
PedroMoss2268

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top