VBL loop help

Stormy1

New Member
Joined
Mar 26, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a very big excel work book. I think there are 108 tabs across the bottom. The first 3 are what I work with then the other 105 hold the data. I have a macro that goes to the 105 tabs and sorts them but for some reason, it is throwing me an error.
I'm getting Run-time '-214731767 (80028029)':
Automation error
Invalid forward reference, or reference to uncompiled type.

Nothing has changed with the tabs, this error just pops up every now and then. Usually I just go back to an earlier version of the workbook and it starts working again for a month or so then this same error will pop up.

This is a copy of the code which performs the same task for every worksheet besides the first 3 that are named Data, Answers and Master. Any ideas why I would randomly be getting this error about once every month or so?

I did try to write a loop code so it would be shorter but I am a complete novice when it comes to code.

Sub Sorter()
'CSE
Application.ScreenUpdating = False

'CSE
Sheets("CSE").Select
Range("A1:I800000").Sort _
Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("C1"), Order2:=xlDescending, Header:=xlYes

'AS
Sheets("AS").Select
Range("A1:I800000").Sort _
Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("C1"), Order2:=xlDescending, Header:=xlYes

'AC
Sheets("AC").Select
Range("A1:I800000").Sort _
Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("C1"), Order2:=xlDescending, Header:=xlYes

Appreciate any help or ideas on how to get this error to clear forever.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi Stormy1,

Try below code assuming data starts from cell A1 in all sheets ...
VBA Code:
Sub test()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Sheets
    Select Case ws.Name
        Case "Data", "Answers", "Master" '<-- change to 3 sheets that you're NOT sorting
        Case Else: ws.[A1].CurrentRegion.Sort Key1:=ws.[A1], Order1:=1, Key2:=ws.[C1], Order2:=2, Header:=xlYes
    End Select
Next

End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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