Hello!
I have this code
Sub Macro1()
Dim rngFilter As Range
Dim sDate1 As Long, sDate2 As Long
Dim sID As String
With Worksheets("macro")
sDate1 = .Range("b1").Value
sDate2 = .Range("b2").Value
sID = .Range("c1").Value
End With
With Worksheets("data")
.Range("A1:c10000").AutoFilter Field:=1, Criteria1:= _
">=" & sDate1, Operator:=xlBetween, Criteria2:="<=" & sDate2
.Range("A1:c10000").AutoFilter Field:=2, Criteria1:=sID
Set rngFilter = .Range("a2").CurrentRegion.Offset(1).SpecialCells(xlCellTypeVisible)
.Range("$A$1").AutoFilter
End With
If Not rngFilter Is Nothing Then
With Worksheets("macro")
.Range("a7:c" & .Cells(6, "c").End(xlDown).Row).ClearContents
rngFilter.Copy .Range("a7")
End With
End If
Dim LR As Long
With Range("a1:C" & Range("A" & Rows.Count).End(xlUp).Row)
LR = .Rows.Count
If .Cells(.Rows.Count, 1).Value <> "Total" Then
LR = .Rows.Count + 3
.Cells(LR, 1).Value = "Total"
End If
.Cells(LR, 3).Formula = "=sum(r6c:r[-1]c)"
.Cells(1, 1).Resize(LR, 3).Font.Bold = True
.Cells(1, 1).Resize(LR, 3).HorizontalAlignment = xlCenter
.Cells(1, 1).Resize(LR, 3).VerticalAlignment = xlBottom
End With
If MsgBox("Do you want to print?", vbYesNo) = vbYes Then
Range("myrange").PrintOut ' or .Preview if you wish to preview the print first.
End If
End Sub
i'd like to modify in the last part the code(the print part) do the named range "myrange" to be dynamic!
Also i use this SUMPRODUCT formula to get back some data from my other sheet.
Formula:
=SUMPRODUCT((Data!$A$2:$A$20<$B$1)*(Data!$B$2:$B$20=$C$1)*(Data!$C$2:$C$20))
As my data sheet will include more that 10000 rows of data i know that the calculations will be too slow..
So can we replace this SUMPRODUCT formula with a code to work faster?
Note: I use SUMPRODUCT because this workbook works also in computers yhan use Excel 2003
Thanks in advance.
Bookmarks