Subscript Out of Range Error

gvillepa

New Member
Joined
Oct 18, 2017
Messages
36
Was hoping you could help this VB beginner.

Keep getting '9' Subscript Out of Range error. Debug brings me to this:

lastrow = Sheets("DB").Range("A356000").End(xlUp).Row + 1

The Range is dynamic and I am think my line code is off since I am trying to set some sort of range. Help please! Thanks,


HTML:
Sub MyMacro()   
 
Dim lastrow As Long       
dTime = Now + TimeValue("00:00:12")    

Application.OnTime dTime, "MyMacro"

lastrow = Sheets("DB").Range("A356000").End(xlUp).Row + 1

Worksheets("1 Minute Refresh").Range("A2:R101").CopyActiveSheet.Paste Destination:=Worksheets("DB").Range("A" & lastrow)

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try
Code:
LastRow = Sheets("DB").Range([COLOR=#0000ff]"A" & Rows.Count[/COLOR]).End(xlUp).Row + 1
 
Upvote 0
Is the sheet name DB spelt correctly? No leading or trailing spaces in the actual sheet name?
Is the workbook that holds it the active one when the code is run?
 
Upvote 0
Hi,
try
Code:
lastrow = ThisWorkbook.Worksheets("DB").Cells(Rows.Count, "A").End(xlUp).Row + 1

Assumes that sheet name DB exists.

Dave
 
Last edited:
Upvote 0
Thanks Fluff. This Worked. I Tried doing just Range ("A") before but overlooked the Rows.Count.

Try
Code:
LastRow = Sheets("DB").Range([COLOR=#0000ff]"A" & Rows.Count[/COLOR]).End(xlUp).Row + 1

I appreciate the problem solved!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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