+ Reply to Thread
Results 1 to 4 of 4

Macro Speed

Hybrid View

  1. #1
    Registered User
    Join Date
    05-10-2011
    Location
    india
    MS-Off Ver
    MS365
    Posts
    28

    Macro Speed

    Hi All

    This is my first macro code, unfortunately it's taking long time to genereate nearely 8 min.

    Need help on this
    Sub report()
    
    Dim F1 As String
    Dim F2 As String
    Dim F3 As String
    
    'Formulas for vlookup
    
    F1 = "=+VLOOKUP(RC[-1], Report Apr 20'!C[-1]:C7,6,0)"
    F2 = "=+VLOOKUP(RC[-2],' Report Apr 20'!C[-2]:C7,5,0)"
    F3 = "=+VLOOKUP(RC[-3],' Report Apr 20'!C[-3]:C6,4,0)"
    
        Columns("C:E").Select
        Selection.Insert Shift:=xlToRight
    [C1].Value = "PC / MAG"
    [D1].Value = "BU / LOB"
    [E1].Value = "BS / BG"
    
    Application.ScreenUpdating = False
    
    
    Range("c2").Select
    Do While IsEmpty(ActiveCell.Offset(0, -1)) = False
        ActiveCell.FormulaR1C1 = F1
        ActiveCell.Offset(1, 0).Select
        Loop
    Range("d2").Select
    Do While IsEmpty(ActiveCell.Offset(0, -1)) = False
        ActiveCell.FormulaR1C1 = F2
        ActiveCell.Offset(1, 0).Select
        Loop
    Range("E2").Select
      Do While IsEmpty(ActiveCell.Offset(0, -1)) = False
        ActiveCell.FormulaR1C1 = F3
        ActiveCell.Offset(1, 0).Select
        Loop
    Last edited by learningkid0808; 05-23-2011 at 07:53 AM. Reason: Fixed Code Tags

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,433

    Re: Macro Speed

    See if this is any quicker:

    Sub reportTMS()
    
    'Formulas for vlookup
    Dim F1 As String: F1 = "=VLOOKUP(RC[-1],'Report Apr 20'!C[-1]:C7,6,0)"
    Dim F2 As String: F2 = "=VLOOKUP(RC[-2],'Report Apr 20'!C[-2]:C7,5,0)"
    Dim F3 As String: F3 = "=VLOOKUP(RC[-3],'Report Apr 20'!C[-3]:C7,4,0)"
    
    Application.ScreenUpdating = False
    
    Columns("C:E").Insert Shift:=xlToRight
    [C1:E1].Value = Split("PC / MAG|BU / LOB|BS / BG", "|")
    
    With Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row)
        .Offset(0, 1).FormulaR1C1 = F1
        .Offset(0, 2).FormulaR1C1 = F2
        .Offset(0, 3).FormulaR1C1 = F3
    End With
    
    Application.ScreenUpdating = True
    End Sub


    Note: if there are a lot of formulae, it might also help to switch calculation to manual and then back to automatic.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-10-2011
    Location
    india
    MS-Off Ver
    MS365
    Posts
    28

    Re: Macro Speed

    Hi TM

    Thanks a lot!!!

    Its working great, saved a lot of time!!! Can you advise how to handle these type of requests in future.

    Regards

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Speed

    A PvotTable might be a better option
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

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