+ Reply to Thread
Results 1 to 7 of 7

performance tuning of vba macro

  1. #1
    Registered User
    Join Date
    12-04-2017
    Location
    australia
    MS-Off Ver
    excel 2007
    Posts
    3

    performance tuning of vba macro

    Hello everyone
    Iam very new to macro, trying to learn the stuff through online .

    I have been trying to make changes to already existing macros , I was successful in making some changes but Iam having issues with performance .

    The macro works well for few rows but it just freezes when I run for large volume ( say 1600 rows) . I think it should not be a issue for 1600 , may be my macro is stuck in a loop and not able to come out .

    The macro looks for the row "bal" and updates the formula in subsequent columns and also does some formatting in the rows "soo" . My main issue is ,it works fine for few rows but when rows increases it freezes . I wanna know is there any command where it updates formula in column range at a time
    I mean instead of looping through each column ( as per below macro) can it set that formula in all columns at a time. below is the part of macro where it loops for updating each column . I really appreciate any help i can get .


    For j = 11 To 50
    'Set each subsequent cell with this formulae
    Cells(i, j).FormulaR1C1 = "=IF(RC[-1]+(R[-1]C-R[-2]C)<=0,0,RC[-1]+(R[-1]C-R[-2]C))"

    Next j
    ############################################################
    Below is the complete macro.

    Sub Nat_View_VP()
    Sheets("National Impact (VP)").Select
    'Find the first cell in the row
    Range("j2").Select
    'Loop
    For i = 1 To ActiveSheet.UsedRange.Rows.Count
    If Cells(i, 9).Value = "Bal" Then
    'Formula for first column
    Cells(i, 10).FormulaR1C1 = "=IF(R[-2]C[-3]+(R[-1]C-R[-2]C)<=0,0,R[-2]C[-3]+(R[-1]C-R[-2]C))"
    'Loop to go through each column
    For j = 11 To 50
    'Set each subsequent cell with this formulae
    Cells(i, j).FormulaR1C1 = "=IF(RC[-1]+(R[-1]C-R[-2]C)<=0,0,RC[-1]+(R[-1]C-R[-2]C))"
    'Colour cell based on its value
    'Cells(i, j).NumberFormat = "#,##0_ ;[Red]-#,##0 "
    Cells(i, j).FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
    Formula1:="=0"
    Cells(i, j).FormatConditions(Cells(i, j).FormatConditions.Count).SetFirstPriority
    With Cells(i, j).FormatConditions(1).Font
    .Bold = True
    .Italic = False
    .Color = -16383844
    .TintAndShade = 0
    End With
    With Cells(i, j).FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent2
    .TintAndShade = 0.799981688894314
    End With
    Cells(i, j).FormatConditions(1).StopIfTrue = False

    Next j
    End If
    If Cells(i, 9).Value = "Fcst" Then
    'Find the cell that is the lead time and colour it Orange.
    Cells(i, 9).Offset(0, Cells(i, 6)).Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = 2
    .ThemeColor = xlThemeColorAccent6
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    With Selection.Font
    .ColorIndex = xlAutomatic
    .TintAndShade = 0
    End With
    End If
    If Cells(i, 9).Value = "SOO" Then
    'Make all the cells have a conditional fill of blue.
    For j = 10 To 50
    Cells(i, j).FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=0"
    Cells(i, j).FormatConditions(Cells(i, j).FormatConditions.Count).SetFirstPriority
    With Cells(i, j).FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 16737843
    .TintAndShade = 0
    End With
    Cells(i, j).FormatConditions(1).StopIfTrue = False
    Next j
    End If
    Next i

    End Sub

  2. #2
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: performance tuning of vba macro

    It's hard to help you with just the information that you have supplied. It might help if you attach the file.

  3. #3
    Registered User
    Join Date
    12-04-2017
    Location
    australia
    MS-Off Ver
    excel 2007
    Posts
    3

    Re: performance tuning of vba macro

    Thanks for the reply . Ya it is better to attach sheet . Iam new to forum, please can you advise how to attach my file , i do not see that option in reply window .

  4. #4
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: performance tuning of vba macro

    You have to hit the 'Go Advanced' button (bottom right).
    Then, toward the bottom (below the text entry window), you will see (in Bold) the word: Attachments.
    To the right of that, you will see a hyperlink: Manage Attachments. This will lead to another page where you can
    browse, attach your file and then upload it. Then, submit your reply. This will send the file.

    It's good to read the Forum Rules from top to bottom. It will help w/ the overall communication back & forth.
    You will see a button at the top labeled Forum Rules. Hope this helps!

  5. #5
    Registered User
    Join Date
    12-04-2017
    Location
    australia
    MS-Off Ver
    excel 2007
    Posts
    3

    Re: performance tuning of vba macro

    Thanks for the reply . I have attached the sheet with macro in it .
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-02-2017
    Location
    India
    MS-Off Ver
    2007
    Posts
    16

    Re: performance tuning of vba macro

    Cannot find the macro in the file

    The file extension may be wrong?

  7. #7
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: performance tuning of vba macro

    Roops218, The file extension must be 'xlsm' to allow it to contain a macro. A 'xlsx' file can not be saved with an intact macro in it. Save it again, with the macro, as an xlsm and attach & re-post. Thanks!

+ 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. 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
  2. [SOLVED] Help with modifying VBA Macro - Works fine but needs fine tuning !
    By stefan27 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2015, 10:27 AM
  3. VBA Performance Tuning on Formulas - Help!
    By excelrabbit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-04-2015, 12:15 AM
  4. Fine tuning a macro...
    By cafc_fuller in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-30-2013, 07:41 AM
  5. [SOLVED] Need help fine tuning a macro
    By jaimeteele in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-27-2013, 04:43 PM
  6. Macro tuning
    By lauren_wing in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2010, 10:47 AM
  7. Great macro for filtering a unique list - some fine tuning
    By pekde in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-24-2010, 01:32 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