Results 1 to 13 of 13

Make print area dynamic & replace a SUMPRODUCT with code!

Threaded View

  1. #1
    Registered User
    Join Date
    06-15-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    85

    Make print area dynamic & replace a SUMPRODUCT with code!

    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: copy to clipboard
    =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.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 09-05-2013, 03:32 AM
  2. [SOLVED] Need ‘Set Print Area’ Code for Dynamic Print Range based on Conditions
    By dosbirn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2013, 12:13 PM
  3. Replies: 2
    Last Post: 01-04-2013, 04:22 PM
  4. Dynamic print area
    By Harley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2005, 09:20 AM
  5. Print Area:What would be the code for setting the print area
    By wammer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2005, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1