I added this thread a while back and it is working fine. However, I am now faced with a twist to the original issue of inserting a new sheet alphabetically.
I have a workbook that, for example, has 22 sheets in it. The first sheet(1) is a Total sheet for the following 10 sheets(doctors). Sheet(12) is another Total sheet for the remaining 10 sheets(hospitals).
I have created an automated process that a user can add a new doctor sheet and it is placed alphabetically from sheet(2), I have coded it to ignore the first sheet. This method works fine for the doctors who's section in the workbook comes first. However, when adding a new hospital sheet, the code places the new hospital alphabetically with the doctors.
If I know the name of the Total sheet for the hospitals, how can I force the insert to start at the Total sheet for the hospitals and start looking to place the new sheet?
Currently, I am using the following code:
Dim oSheet as Object
Dim strNewLocation as String
Dim strAfter as String
For Each oSheet In Application.Workbooks("Totals.xls"
.Worksheets
If oSheet.Name = "TOTALPHYSICIAN" Then
GoTo ERR_SKIP_SHEET
ElseIf oSheet.Name > UCase(strNewLocation) Then
oSheet.Activate
strAfter = oSheet.Name
Exit For
End If
ERR_SKIP_SHEET:
Next oSheet
Sheets(strNewLocation).Move Before:=Sheets(strAfter)
Any ideas are appreciated.
I have a workbook that, for example, has 22 sheets in it. The first sheet(1) is a Total sheet for the following 10 sheets(doctors). Sheet(12) is another Total sheet for the remaining 10 sheets(hospitals).
I have created an automated process that a user can add a new doctor sheet and it is placed alphabetically from sheet(2), I have coded it to ignore the first sheet. This method works fine for the doctors who's section in the workbook comes first. However, when adding a new hospital sheet, the code places the new hospital alphabetically with the doctors.
If I know the name of the Total sheet for the hospitals, how can I force the insert to start at the Total sheet for the hospitals and start looking to place the new sheet?
Currently, I am using the following code:
Dim oSheet as Object
Dim strNewLocation as String
Dim strAfter as String
For Each oSheet In Application.Workbooks("Totals.xls"
If oSheet.Name = "TOTALPHYSICIAN" Then
GoTo ERR_SKIP_SHEET
ElseIf oSheet.Name > UCase(strNewLocation) Then
oSheet.Activate
strAfter = oSheet.Name
Exit For
End If
ERR_SKIP_SHEET:
Next oSheet
Sheets(strNewLocation).Move Before:=Sheets(strAfter)
Any ideas are appreciated.