+ Reply to Thread
Results 1 to 3 of 3

Enhance macro performance

Hybrid View

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    55

    Enhance macro performance

    Hi Excel Gurus,

    I am novice with VBA. I have created a macro through recording macro and modified it using my little knowledge of VBA, however this macro is taking too much time.

    The macro is just pasting a formula in each cell of a range and pasting that cell as values.

    Can someone please review this macro enhance it performace.


    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
    Dim Cell As Range
    Application.ScreenUpdating = False
    With Worksheets("Sheet1")
    For Each Cell In .Range("J2:J9586")
        'Range("J2").Select
        Cell.FormulaR1C1 = _
            "MY FORMULA"
        Cell.Copy
        Cell.PasteSpecial xlPasteValues
        Next
    End With
        'Range("J3").Select
        'Range("J2").Select
    Application.ScreenUpdating = True
    End Sub
    Thanks,
    Charm

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Enhance macro performance

    You don't need to loop through each cell. Try:
    Sub Macro1()
        On Error GoTo Terminate
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        With Worksheets("Sheet1").Range("J2:J9586")
            .FormulaR1C1 = "MY FORMULA"
            .Value = .Value
        End With
        
    Terminate:
        If Err Then
            Debug.Print "Error", Err.Number, Err.Description
            Err.Clear
        End If
        
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Enhance macro performance

    Many many thanks, Olly

    This is lightning fast

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. performance tuning of vba macro
    By Roopa218 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-06-2017, 09:03 AM
  2. current moth MTD performance with last year same month same days performance
    By satyanarayana in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-03-2015, 03:36 AM
  3. [SOLVED] Macro needs a guru to enhance and insert a particular funtion of control execution.
    By Darkprophecy in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 04-08-2015, 04:32 AM
  4. Macro performance
    By toravietl in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-21-2014, 05:28 PM
  5. VBA Arrays macro performance
    By sepi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2013, 08:21 AM
  6. Poor Macro Performance
    By ckm08 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-07-2011, 04:36 AM
  7. Irregular Macro Performance
    By lostit in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 07-23-2009, 04:17 PM

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