Run-time error '9': Subscript out of range

Hazelwood

New Member
Joined
Feb 25, 2018
Messages
13
I get the "Run-time error '9': Subscript out of range" error when running my macro from a Button assigned to my macro, but if I run my macro from the ribbon it works fine. (When I debug, it says the problem is with the "LastRow =" line. Don't understand why.

Table256 is the only table and only data on the Members tab - my row is successfully added to my table

I'm running this on a mac ... Looking for some help to understand problem

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00 ; background-color: #ffffff }p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff ; min-height: 13.0px}span.s1 {color: #011993}</style>Sub GetLastRow()


Dim sht As Worksheet
Dim LastRow As Long
Set sht = ActiveSheet

Sheets("Members").Select

ActiveSheet.ListObjects("Table256").ListRows.Add AlwaysInsert:=True

LastRow = sht.ListObjects("Table256").Range.Rows.Count

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi & welcome to the board
Try
Code:
Sub GetLastRow()


Dim sht As Worksheet
Dim LastRow As Long
Set sht = Sheets("Members")


sht.ListObjects("Table256").ListRows.Add AlwaysInsert:=True

LastRow = sht.ListObjects("Table256").Range.Rows.Count

End Sub
Your problem was probably due the the Members sheet not being the active sheet when you ran the macro
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,449
Members
449,160
Latest member
nikijon

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