+ Reply to Thread
Results 1 to 4 of 4

Macro Inserts row above the word Type and Highlights is taking too long to run.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-08-2013
    Location
    FLORENCE, ALABAMA
    MS-Off Ver
    Excel 2010
    Posts
    125

    Macro Inserts row above the word Type and Highlights is taking too long to run.

    Hello Excel Experts,
    I have a macro that inserts a row above the word "Type" in column A. The macro works great, but it's like I am stuck in an infinite loop which makes the macro run way too long. Is there a way I can set a range that the first row starts at row A11 and the last row will be A100? Or even better, can I select row A11 down to the last row and have the macro run on the select rows? I would appreciate any help on this. Thank you!!!
    Sub InsertRow()
        Dim Lastrow As Long
        Dim I As Long
        Application.ScreenUpdating = False
        Lastrow = Range("A" & Rows.Count).End(xlUp).Row
        I = 1
        While I <= Lastrow
            If (Len(Cells(I, "A")) <> Len(Replace(Cells(I, "A"), "Type", ""))) Then
                Rows(I & ":" & I).Insert shift:=xlDown
                Rows(I & ":" & I).Interior.ColorIndex = 16
                I = I + 1
            End If
            I = I + 1
            Lastrow = Range("A" & Rows.Count).End(xlUp).Row
        Wend
        Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro Inserts row above the word Type and Highlights is taking too long to run.

    First question:

    Sub TAMMY32()
        Dim Lastrow As Long
        Dim I As Long
        With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        End With
        Lastrow = 100
        I = 11
        While I <= Lastrow
            If (Len(Cells(I, "A")) <> Len(Replace(Cells(I, "A"), "Type", ""))) Then
                Rows(I & ":" & I).Insert shift:=xlDown
                Rows(I & ":" & I).Interior.ColorIndex = 16
                I = I + 1
            End If
            I = I + 1
            Lastrow = Range("A" & Rows.Count).End(xlUp).row
        Wend
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    End Sub
    Second question:

    Sub TAMMY32()
        Dim Lastrow As Long
        Dim I As Long
        With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        End With
        Lastrow = Range("A" & Rows.Count).End(xlUp).Row
        I = 11
        While I <= Lastrow
            If (Len(Cells(I, "A")) <> Len(Replace(Cells(I, "A"), "Type", ""))) Then
                Rows(I & ":" & I).Insert shift:=xlDown
                Rows(I & ":" & I).Interior.ColorIndex = 16
                I = I + 1
            End If
            I = I + 1
            Lastrow = Range("A" & Rows.Count).End(xlUp).row
        Wend
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    05-08-2013
    Location
    FLORENCE, ALABAMA
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Macro Inserts row above the word Type and Highlights is taking too long to run.

    Dear John H. D,
    It worked beautifully. It went faster using the Lastrow = 100, I = 11. Thank you so much for the help.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro Inserts row above the word Type and Highlights is taking too long to run.

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. Replies: 4
    Last Post: 09-16-2015, 08:07 AM
  2. [SOLVED] Macro is taking very long to complete
    By kevivu in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-02-2015, 03:53 AM
  3. Import .csv macro taking too long
    By Ctomo in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-31-2013, 07:58 AM
  4. Macro taking too long to finish
    By DKAbi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-17-2013, 06:23 PM
  5. Macro taking too long to execute
    By jacob@thepenpoint in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2012, 05:13 PM
  6. Excel 2007 : Macro taking a long period of time
    By Nikeyg in forum Excel General
    Replies: 2
    Last Post: 09-07-2011, 07:37 AM
  7. Macro taking too long time to run
    By sharmanjali87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2010, 07:08 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