+ Reply to Thread
Results 1 to 6 of 6

How to improve performance for a Macro checking cells out in a big range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-12-2008
    Location
    Schleswig-Holstein, Germany
    MS-Off Ver
    2010
    Posts
    102

    How to improve performance for a Macro checking cells out in a big range

    ...Hi everybody,

    I need some help again from a VBA Guru probably...

    Iīve created this little Macro below to change the font color of some cells on a table...

    Sub ResetCellFormats()
    Set TargetCells = Range("C:AI,AL:GE")
    
    If [ConditionalTextFormattingButton] = 3 Then
    
        For Each cell In TargetCells
        If cell.Font.ColorIndex = 26 Then cell.Font.ColorIndex = 1
        Next
    
    End If
    End Sub

    The problem is, the table Iīm applying the Macro to is so big that it take ages...2248 rows !!

    isnīt there another more efficient way to approach this aim with VBA Code?

    As you can see in the code above, itīs only abaout changing the font color to black for the cell values in the table containing a magenta color font...

    Thanks in advance for your help,
    Ruben

  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
    44,733

    Re: How to improve performance for a Macro checking cells out in a big range

    Range("C:AI,AL:GE")
    is not processing 2248 rows, it is processing 1,048,576 rows by a lot of columns. That's why it's slow.
    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
    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
    44,733

    Re: How to improve performance for a Macro checking cells out in a big range

    Maybe:

    Sub ResetCellFormats()
    Dim TargetCells As Range, cell As Range
    Set TargetCells = Range("C1:AI2248,AL1:GE2248")
    
    If [ConditionalTextFormattingButton] = 3 Then
    
        For Each cell In TargetCells
            If cell.Font.ColorIndex = 26 Then cell.Font.ColorIndex = 1
        Next
    
    End If
    End Sub

  4. #4
    Forum Contributor
    Join Date
    05-12-2008
    Location
    Schleswig-Holstein, Germany
    MS-Off Ver
    2010
    Posts
    102

    Re: How to improve performance for a Macro checking cells out in a big range

    Hello TMS,

    Thanks a lot! it has worked out great .... Now it only takes less than a minute!...I had missed this crucial fact:
    is not processing 2248 rows, it is processing 1,048,576 rows by a lot of columns. That's why it's slow.

  5. #5
    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
    44,733

    Re: How to improve performance for a Macro checking cells out in a big range

    You're welcome.

    This should make it faster:

    Option Explicit
    
    Sub ResetCellFormats()
    Dim TargetCells As Range, cell As Range
    Set TargetCells = Range("C1:AI2248,AL1:GE2248")
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    If [ConditionalTextFormattingButton] = 3 Then
    
        For Each cell In TargetCells
            If cell.Font.ColorIndex = 26 Then cell.Font.ColorIndex = 1
        Next
    
    End If
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    End Sub

  6. #6
    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
    44,733

    Re: How to improve performance for a Macro checking cells out in a big range

    Thanks for the rep.

+ 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. 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
  2. [SOLVED] Can VBA improve the performance of this spreadsheet
    By gassiusmax in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2014, 05:19 AM
  3. improve performance
    By david90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2013, 01:12 AM
  4. Improve Performance of Form with 80 Dlookups
    By Whizbang in forum Access Tables & Databases
    Replies: 3
    Last Post: 10-18-2011, 05:11 PM
  5. How to improve the performance of a looping UDF
    By johnnycanuck in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-03-2011, 01:39 PM
  6. How to improve macro performance for copying rows from one sheet to another
    By jonny_chanook in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2011, 09:41 AM
  7. [SOLVED] PageBreak problem. How to improve performance?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2005, 09:05 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