Results 1 to 7 of 7

Improve Speed: VBA Code very slow due to changing cell values in for loop

Threaded View

  1. #1
    Registered User
    Join Date
    01-13-2020
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2019
    Posts
    8

    Improve Speed: VBA Code very slow due to changing cell values in for loop

    Much as the title says. I have the following piece of VBA code:

    Sub Filtering()
    Application.ScreenUpdating = False
    Numrows = Range("L6").Value
    Num_Unique_Codes = Range("J6").Value
    
    For i = 20 To Num_Unique_Codes
        Name = Range("O20:O" & i)
        Range("A19:L" & Numrows).AutoFilter Field:=7, Criteria1:=Name
        Range("K5") = Application.Sum(Range("C20:C" & Numrows).SpecialCells(xlCellTypeVisible))
        If Range("K5") = 0 Then
            Range("A20:L" & Numrows).SpecialCells(xlCellTypeVisible).Clear
    
        End If
        
    ActiveSheet.ShowAllData
    Next i
    
    
    Application.ScreenUpdating = True
    End Sub
    This works 100% perfectly from a functionality point of view, but is very slow. I know enough about vba to understand that it is likely due to how often I am changing physical excel cells instead of dealing with a range, but not enough to no where to go with fixing it.

    I've attached an excel file that shows what it does. Macros 1-4 work. Macro 5 (the code included above) is the slow one, although it works.

    Functionality Wise, this is what I'm doing:

    Counting the rows (quick enough)
    Finding all the unique names and counting them (quick enough)
    Filtering by each unique name, and if the values of each unique name sum to 0, clearing the cells (this is slow)
    Tidying up by deleting all the unique names and all the rows I cleared.

    Any help appreciated
    Last edited by Nick_G; 02-03-2020 at 03:35 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replace Code to improve processing speed for copy & paste
    By paula.mccall in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2019, 01:04 PM
  2. For Loop Code is Very Slow - How can I speed it up?
    By maym in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2019, 03:53 AM
  3. How to improve performance of my code?, now is too slow!!
    By Laurelb in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-25-2015, 03:15 PM
  4. [SOLVED] Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-10-2013, 11:16 AM
  5. [SOLVED] How to improve speed of VBA code while using Vlookup function
    By Narasimharao Nandula in forum Excel Programming / VBA / Macros
    Replies: 38
    Last Post: 08-02-2013, 11:20 PM
  6. How to improve the running speed of this VBA macro code?
    By sellim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2012, 01:45 PM
  7. [SOLVED] Speed up slow macro loop
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-15-2012, 11:41 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