Results 1 to 12 of 12

Long VBA Code - Improve Efficiency?

Threaded View

  1. #1
    Registered User
    Join Date
    08-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Long VBA Code - Improve Efficiency?

    I have a very slow, time consuming macro (takes approx 25 mins to run on i7 32GB), that throws up the lack of resource Excel error and I was hoping somebody with more knowledge on VBA had any tips to improve the code and make it more efficient?

    Part of the code below...

    Any help greatly appreciated



    Sub Master()
    Application.ScreenUpdating = False
    Sheets("Sales Data").Select
    
    Range("A2:A" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IFERROR(VLOOKUP(T2,Notes!$B:$F,5,1),"""")"
    Range("A2:A" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("A2:A" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("B2:B" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=W2&A2"
    Range("B2:B" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("B2:B" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("C2:C" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=V2&A2"
    Range("C2:C" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("C2:C" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("D2:D" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IFERROR(VLOOKUP(U2,'Top Sellers'!$L:$O,4,0),"""")"
    Range("D2:D" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("D2:D" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("E2:E" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IFERROR(VLOOKUP(U2,'Top Sellers'!$G:$J,4,0),"""")"
    Range("E2:E" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("E2:E" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("F2:F" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IFERROR(VLOOKUP(U2,'Top Sellers'!$B:$E,4,0),"""")"
    Range("F2:F" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("F2:F" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("G2:G" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=A2&D2"
    Range("G2:G" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("G2:G" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("H2:H" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=A2&W2&E2"
    Range("H2:H" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("H2:H" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("I2:I" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=A2&V2&F2"
    Range("I2:I" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("I2:I" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("S2:S" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=A2&U2"
    Range("S2:S" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("S2:S" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("L2:L" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IF(D2=""Y"",S2&COUNTIF(S$2:S2,S2),"""")"
    Range("L2:L" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("L2:L" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("K2:K" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IF(L2=S2&""1"",""Y"","""")"
    Range("K2:K" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("K2:K" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("J2:J" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IF(K2=""Y"",A2&K2,"""")"
    Range("J2:J" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("J2:J" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("O2:O" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IF(E2=""Y"",S2&COUNTIF(S$2:S2,S2),"""")"
    Range("O2:O" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("O2:O" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("N2:N" & Cells(Rows.Count, 20).End(xlUp).Row).Formula = "=IF(O2=S2&""1"",""Y"","""")"
    Range("N2:N" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("N2:N" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
        
        
    Sheets("Fixed").Select
    
    
    Range("K2:R2").Select
        Selection.Copy
     Range("K5:R" & Cells(Rows.Count, 8).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("K5:R" & Cells(Rows.Count, 8).End(xlUp).Row).Select
            Selection.Copy
    Range("K5:R" & Cells(Rows.Count, 8).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("W2:AD2").Select
        Selection.Copy
     Range("W5:AD" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("W5:AD" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("W5:AD" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
         
    Range("AI2:AP2").Select
        Selection.Copy
     Range("AI5:AP" & Cells(Rows.Count, 32).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("AI5:AP" & Cells(Rows.Count, 32).End(xlUp).Row).Select
            Selection.Copy
    Range("AI5:AP" & Cells(Rows.Count, 32).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
        
        
        
        
        
    Range("AU2:BB2").Select
        Selection.Copy
     Range("AU5:BB" & Cells(Rows.Count, 8).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("AU5:BB" & Cells(Rows.Count, 8).End(xlUp).Row).Select
            Selection.Copy
    Range("AU5:BB" & Cells(Rows.Count, 8).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("BG2:BN2").Select
        Selection.Copy
     Range("BG5:BN" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("BG5:BN" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("BG5:BN" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
         
    Range("BS2:BZ2").Select
        Selection.Copy
     Range("BS5:BZ" & Cells(Rows.Count, 32).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("BS5:BZ" & Cells(Rows.Count, 32).End(xlUp).Row).Select
            Selection.Copy
    Range("BS5:BZ" & Cells(Rows.Count, 32).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
        
        
        
        
        
    Range("CE2:CL2").Select
        Selection.Copy
     Range("CE5:CL" & Cells(Rows.Count, 8).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("CE5:CL" & Cells(Rows.Count, 8).End(xlUp).Row).Select
            Selection.Copy
    Range("CE5:CL" & Cells(Rows.Count, 8).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("CQ2:CX2").Select
        Selection.Copy
     Range("CQ5:CX" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("CQ5:CX" & Cells(Rows.Count, 20).End(xlUp).Row).Select
            Selection.Copy
    Range("CQ5:CX" & Cells(Rows.Count, 20).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
         
    Range("DC2:DJ2").Select
        Selection.Copy
     Range("DC5:DJ" & Cells(Rows.Count, 32).End(xlUp).Row).PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("DC5:DJ" & Cells(Rows.Count, 32).End(xlUp).Row).Select
            Selection.Copy
    Range("DC5:DJ" & Cells(Rows.Count, 32).End(xlUp).Row).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Application.ScreenUpdating = True
    
    
    End Sub
    Last edited by Dgp2012; 07-18-2013 at 11:29 AM.

Thread Information

Users Browsing this Thread

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

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