+ Reply to Thread
Results 1 to 2 of 2

How to avoid cell SELECTION but still format cells to speed up the macro running speed

  1. #1
    Registered User
    Join Date
    05-05-2018
    Location
    Birmingham, England
    MS-Off Ver
    2010
    Posts
    1

    How to avoid cell SELECTION but still format cells to speed up the macro running speed

    Hi,

    I have the following code that checks for a condition in the range, and if it is a ‘1’ then it select some cells and formats them (by changing the interior colour, interior.ThemeColor and Font.ThemeColor).

    The problem is that, as the program loops through so many cells, it selects many – prior to making the changes – and the macro is very very slow.

    I’m looking either (1) for a way to avoid the cell selection* but use the same basic principle or (2) alternative way all together.

    * I’ve found that I can do StatusMarker.Offset(0, 6).Interior.Color = 5296274 but this method doesn’t work with the ThemeColour requirements.

    The macro’s far too slow and any help will be really appreciated – code below:

    'Count Number of Green Ticks and Record
    'If Green Tick in Completed Column)Green Each Process Stream Description Cell/Grey Time Columns
    '1st Process Stream
    'Set Counters
    y = 0
    z = 0
    For Each StatusMarker In StatusTimeSpan
    If StatusMarker.Offset(0, 5) = 1 Then
    y = y + 1 'MsgBox x
    StatusMarker.Offset(0, 6).Select
    Selection.Interior.Color = 5296274
    Range(StatusMarker.Offset(0, 2), StatusMarker.Offset(0, 4)).Select
    Selection.Interior.ThemeColor = xlThemeColorDark2
    Selection.Font.ThemeColor = xlThemeColorDark2
    End If
    Next StatusMarker 'MsgBox x
    Sheets("Data").Range("B8").Value = y

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: How to avoid cell SELECTION but still format cells to speed up the macro running speed

    please always use code tags (#-icon) to make it more easier to read

    in essence that is easy the do..
    after each .select you see a next line with selection. combine the two lines by removing both the select an selection part

    Please Login or Register  to view this content.
    The last part you could also use an with.. end with. This allows you to manipulate multiple properties for specific range

    Please Login or Register  to view this content.

+ 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. [SOLVED] Increase VBA speed when running mutiple macros
    By Venterpj1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2016, 04:19 AM
  2. [SOLVED] Speed up macro running time
    By rajeshn_in in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-16-2016, 09:43 PM
  3. Everage Speed km/time (european speed)
    By GerryZucca in forum Excel General
    Replies: 3
    Last Post: 02-23-2015, 03:02 PM
  4. type machine name and have its running speed automatically selected
    By siye in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-06-2014, 08:36 AM
  5. 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
  6. speed of running vba script
    By Jan Paling in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2008, 02:46 PM
  7. Speed up pivot table VBA code, avoid multiple recalculations
    By Ronny in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2005, 04:00 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