+ Reply to Thread
Results 1 to 5 of 5

Loop Through Rows faster

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    59

    Loop Through Rows faster

    Hi All,

    I need help with my code to make it loop faster. I have this code in my Format Report routine. My report runs and then the Formatting is done at the end.

    It inserts a column, HLINK as the first field and then loops from first row to the last row containing data to insert a hyperlink on the first column. Since the number of rows maybe from 1000 or more,
    it takes a while to loop. Is there a way to make this fast?

        Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("A1").Value = " HLINK"   
        hlink = Parameters.Range("UrlServerAddress").Value
        With ActiveSheet
        col = FindCol("HLINK", 1, .Name)
        LastRow = .Range("A1").CurrentRegion.Rows.Count
        If col > 0 Then
            For rw = 2 To LastRow
            Cells(rw, col).Select       
                'Make a call to API and pass parameters to HLINK.
                ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="http://" & hlink & "/cgi /PControl.cgi?tool= HLINK&sc=" & str & "&ph=" & Range("K" & rw).Value _
                & "&stme=" & Range("Y" & rw).Value & "&etme=" & etme, TextToDisplay:="HLINK"
                
                Range(.Cells(2, col), .Cells(LastRow, col)).Value = " HLINK"
                Range(.Cells(2, col), .Cells(LastRow, col)).Font.Underline = True
                Range(.Cells(2, col), .Cells(LastRow, col)).Font.Color = vbBlue
            
            Next rw
        End If
        End With
    Thanks,
    Rollin

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Loop Through Rows faster

    Rollin

    Couldn't you use the HYPERLINK function for the hyperlink?

    If you could then you wouldn't need to loop.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: Loop Through Rows faster

    Hi,
    Thanks. Can you please explain how my code would work with the HYPERLINK function?

    an example would help.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Loop Through Rows faster

    Not sure about your exact URL but it might look something like this.
                 strURL = "http://" & hlink & "/cgi /PControl.cgi?tool= HLINK&sc=" & str & "&ph=""&K2&""" & _
                 "&stme=""&Y2&""&etme=" & etme
                
                With Range(Cells(2, col), Cells(lastrow, col))
                    .Formula = "=HYPERLINK(""" & strURL & """,""HLINK"")"
                    .Font.Underline = True
                    .Font.Color = vbBlue
                End With
    Note, you might not need the font formatting part.

  5. #5
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: Loop Through Rows faster

    Adding "Application.ScreenUpdating = False" before the loop starts might help. Also setting the worksheet recalculation to False might help.

+ 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] For Each Loop (Make it Faster)
    By ExcelQuestion in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-03-2015, 11:36 PM
  2. [SOLVED] faster way to loop
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-22-2015, 12:09 PM
  3. Is there a faster way than a loop to delete rows that satisfy a criteria
    By mortphil in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 12:14 PM
  4. Is it possible to get rid of this loop to make the code faster?
    By mhw1129 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2011, 09:03 AM
  5. Make loop run faster
    By losmi8 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-20-2010, 01:11 AM
  6. Making a simple loop faster
    By gummi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-23-2008, 07:07 PM
  7. [SOLVED] Faster For-Next Loop?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2005, 06:06 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