MACRO keeps falling out

VBA_Newbie1981

New Member
Joined
Sep 1, 2017
Messages
4
Hi,

I am new to Macros. Have written this simple macro but it keeps falling out at the line in RED? any suggestions?
Rich (BB code):
Sub GlassMacro1()
'
' GlassMacro1 Macro
' Add Sheets & put them in order
'
'
    Sheets("Sheet1").Name = "Raw Data DB Viewer"
    Sheets("Sheet2").Name = "Working Data DB Viewer"
    Sheets("Sheet3").Name = "Peoplesoft Download"
    Sheets("Sheet4").Select
    Sheets("Sheet4").Name = "Reconciliation"
    Range("C38").Select
    Sheets("Raw Data DB Viewer").Select
    Cells.Select
    Selection.Copy
    Sheets("Working Data DB Viewer").Select
    ActiveSheet.Paste
    Sheets("Raw Data DB Viewer").Select
    Range("A1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "COMP ID"
    Range("A1").Select
    Sheets("Raw Data DB Viewer").Select
    Sheets("Raw Data DB Viewer").Move After:=Sheets(4)
    Sheets("Reconciliation").Select
    Sheets("Reconciliation").Move Before:=Sheets(1)
    Sheets("Working Data DB Viewer").Select
    Range("A1").Select
End Sub
 
Last edited by a moderator:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Welcome to the forum. :)

What does "falling out" mean? If you're getting an error, what is the error message?
 
Upvote 0
The error message is as follows:

Run-time error '9':

Subscript out of range

Then when I open the DeBug tool - the line at which the problem lies is the line in my original post that is Red (from my understanding)
 
Upvote 0
That means that there isn't a sheet called Sheet2 in the active workbook.
 
Upvote 0
That error is raised because you do not have a sheet named Sheet2
 
Upvote 0
Ok so how do I fix my macro? is there a specific way my code should be written to add a new sheet and then rename the new sheet?
 
Upvote 0
You can do this:

Code:
Sheets.Add.Name = "Working Data DB Viewer"
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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