ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ordering Worksheets (https://www.excelbanter.com/excel-programming/348675-ordering-worksheets.html)

PGalla06[_21_]

Ordering Worksheets
 

I'm trying to create a macro that puts the worksheets in my workbook in
a specific order. Problems arise when certain workbooks are not
created because of missing information. Below is a piece of the code
that I wrote to skip over worksheets that don't exist in my workbook:


E1:
On Error GoTo E2
Sheets("RegionGraphs").Move Befo=Sheets(i)
i = i + 1
Exit Sub
E2:
On Error GoTo E3
Sheets("RegionWorksheet").Move Befo=Sheets(i)
i = i + 1
Exit Sub
E3:

However, the code keeps breaking because of a subscript error. Can you
anyone help to debug this code or suggest an easier way to order my
worksheets?


--
PGalla06
------------------------------------------------------------------------
PGalla06's Profile: http://www.excelforum.com/member.php...o&userid=24260
View this thread: http://www.excelforum.com/showthread...hreadid=495320


Bob Phillips[_6_]

Ordering Worksheets
 
Try this

Dim sh As Worksheet

Set sh = Nothing
On Error Resume Next
Set sh = Worksheets("RegionGraphs")
If Not sh Is Nothing Then
sh.Move Befo=Sheets(i)
i = i + 1
Exit Sub
Else
Set sh = Sheets("RegionWorksheet")
If Not sh Is Nothing Then
sh.Move Befo=Sheets(i)
i = i + 1
Exit Sub
End If
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"PGalla06" wrote in
message ...

I'm trying to create a macro that puts the worksheets in my workbook in
a specific order. Problems arise when certain workbooks are not
created because of missing information. Below is a piece of the code
that I wrote to skip over worksheets that don't exist in my workbook:


E1:
On Error GoTo E2
Sheets("RegionGraphs").Move Befo=Sheets(i)
i = i + 1
Exit Sub
E2:
On Error GoTo E3
Sheets("RegionWorksheet").Move Befo=Sheets(i)
i = i + 1
Exit Sub
E3:

However, the code keeps breaking because of a subscript error. Can you
anyone help to debug this code or suggest an easier way to order my
worksheets?


--
PGalla06
------------------------------------------------------------------------
PGalla06's Profile:

http://www.excelforum.com/member.php...o&userid=24260
View this thread: http://www.excelforum.com/showthread...hreadid=495320





All times are GMT +1. The time now is 12:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com