subscript out of range error

TooMacho

New Member
Joined
Dec 4, 2017
Messages
4
Hello, please i need help i constantly getting subscript out of range error and i dont know why this is my code (i'm begginer)

Sub PrvyPokus()
Dim dátum As String
Dim TotalNLos, Loss10 As Integer
Dim GrossLoss As Long

Workbooks.Open ("R:\93824000 - Riadenie rizík - Skupina SR\VRM Folders\OpRisk a BCM\xMichal ****a\Dashboard\Dashboard_graf -aug_IRR.xlsm")

Workbooks.Open("R:\93824000 - Riadenie rizík - Skupina SR\VRM Folders\OpRisk a BCM\xMichal ****a\Dashboard\SAP.xlsx").Activate
Sheets("report1").Move after:=Workbooks("Dashboard_graf -aug_IRR.xlsm").Sheets("Graf Neg. Loss")
'report2 is giving me the error but when I write "worksheets("name").activate" it will work
Sheets("report2").Move after:=Workbooks("Dashboard_graf -aug_IRR.xlsm").Sheets("Graf Neg. Loss")
ActiveWorkbook.Close savechanges:=False

Workbooks.Open("R:\93824000 - Riadenie rizík - Skupina SR\VRM Folders\OpRisk a BCM\xMichal ****a\Dashboard\LORD - Operation risk dpt. _monthly.xls").Activate
'but this line of code belove is not working after i write that mentioned code and this will not work even if i write the same code "worksheets("name").activate"
Sheets("Negative Losses").Move after:=Workbooks("Dashboard_graf -aug_IRR.xlsm").Sheets("Graf Neg. Loss")
ActiveWorkbook.Close savechanges:=False

Workbooks("Dashboard_graf -aug_IRR").Activate
Sheets("Negative Losses").Activate

GrossLoss = Range("CVNŠ")
TotalNLos = Range("PNŠ")
Loss10 = Range("PNŠvýš10k")
dátum = InputBox("Zadajte dátum")

Sheets("Graf Neg. Loss").Activate

Range("A2").End(xlDown).Offset(1, 0).Select
ActiveCell.Value = dátum
ActiveCell.Offset(0, 1) = TotalNLos
ActiveCell.Offset(0, 2) = Loss10
ActiveCell.Offset(0, 3) = GrossLoss

End Sub

When i try to run this i'm getting that error. But the funny thing is when im clicking on "step into" through the code it works and it is doing what i want it to do. Thins is really confusing and frustrating. Please help. Thank you
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Where do you get the error?
 
Upvote 0
here : "Sheets("report2").Move after:=Workbooks("Dashboard_graf -aug_IRR.xlsm").Sheets("Graf Neg. Loss")" but when i write "worksheets("name").activate" it will work bu then it will do the same thing in "Sheets("Negative Losses").Move after:=Workbooks("Dashboard_graf -aug_IRR.xlsm").Sheets("Graf Neg. Loss")" but the "worksheets("name").activate" line is not working for thin anymore.
 
Upvote 0
Which workbook is the sheet you are trying to move 'report2' in?
 
Upvote 0
Sorry i don't understand. Are you asking me in which workbook i'm trying to move sheet "report 2" ?
 
Upvote 0

Forum statistics

Threads
1,216,526
Messages
6,131,187
Members
449,631
Latest member
mehboobahmad

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