madhattt

New Member
Joined
Jul 26, 2012
Messages
6
I have a workbook that has around 125 sheets and it is always changing. I use the second sheet as an Index. This macro below runs when I activate the Index Sheet. It takes around 4 seconds to run through. I use it very often and the time really adds up. Does anyone have any suggestions on how to speed it up? Any little bit will save me a lot of time!


Code:
Private Sub Worksheet_Activate()

Dim sheetnum As Integer, i As Integer, j As Integer, sheetname As String


Application.ScreenUpdating = False
Application.EnableEvents = False

Range("A:A").ClearContents
Range("B:B").ClearContents
Range("A1").Value = "WPS INDEX"

sheetnum = ActiveWorkbook.Sheets.Count
j = 2

For i = 1 To sheetnum
    sheetname = ActiveWorkbook.Sheets(i).Name
    If sheetname = "WPS INDEX" Then
      Else
        Cells(j, 1).Value = sheetname    'this part inserts the sheet name in column A
        ActiveSheet.Hyperlinks.Add Cells(j, 1), "", "'" & sheetname & "'" & "!A1"    'this part adds the hyperlink
        Cells(j, 2).Value = i    'this part adds the sheet number to column B
        j = j + 1
    End If
Next i

Cells(1, 1).Select
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
ActiveWindow.Zoom = 120

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Thank you in advance for any suggestions!!!!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I'm not the most knowledgable, but it looks like ou have a pretty streamlined code. The only thing I can think of is if you have calculations running, it MIGHT be slowing things down.

If you add

Application.Calculation = xlCalculationManual ' With the Screenupdating
Application.Calculation = xlCalculationAutomatic ' at the end

It MAY speed things up a little.
 
Upvote 0
THAT WAS IT!!! Thank you. It is taking no time at all now. As fast as the click of the mouse. Great advice. I would have never thought calculation had anything to do with it. Thank you!! You saved me an incredible amount of time with this!
 
Upvote 0

Forum statistics

Threads
1,216,462
Messages
6,130,781
Members
449,591
Latest member
sharmavishnu413

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top