Vba Get last used row of a Table

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,621
Office Version
  1. 2021
Platform
  1. Windows
I use this line of code to find last used row in column "A"
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

But how do I do this to find last used row in column "A" Table1
Or last used row of Table1
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This works for me:
Code:
With Range("Table1")
 LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
 Debug.Print LastRow
End With
Table address: D10:H22, with a single cell containing "x" in D15
 
Last edited:
Upvote 0
Thanks Jack that works great.
This works for me:
Code:
With Range("Table1")
 LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
 Debug.Print LastRow
End With
Table address: D10:H22, with a single cell containing "x" in D15
 
Upvote 0
This works for me:
Code:
With Range("Table1")
 LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
 Debug.Print LastRow
End With
Table address: D10:H22, with a single cell containing "x" in D15

Hi, JackDanIce
Actually your code didn't work as I expected.
I think using 'Find' is more accurate then using 'End(xlUp)'.
Here's an example:

Code:
Sub dssgd()
Debug.Print Range("Table1").Address
With Range("Table1")
 Lastrow = .Cells(.Rows.count, 1).End(xlUp).row
  Debug.Print "Lastrow :" & Lastrow
End With

j = Range("Table1").Columns(1).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
k = Range("Table1").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
Debug.Print "j :" & j
Debug.Print "k :" & k
End Sub


Book1
ABC
1
2asddd
3a1
4b2
5a4
6b4
7a3
8b6
97
108
11a
12
13
14
Sheet1


debug.print result:
$A$3:$B$11
Lastrow :8
j :11
k :11
 
Upvote 0
Sorry, the table area was not clear in the previous post.
It's range is $A$3:$B$11

Book1
ABC
1
2asddd
3a1
4b2
5a4
6b4
7a3
8b6
97
108
11a
12
13
Sheet1
 
Upvote 0
Yes now that I work with more it's not doing what I wanted.
And I'm not sure what this means:
"Table address: D10:H22, with a single cell containing "x" in D15"


I thought just using Range("Table1") would tell the script the range

And as the table grows the range would grow. <!-- edit note -->





This works for me:
Code:
With Range("Table1")
 LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
 Debug.Print LastRow
End With
Table address: D10:H22, with a single cell containing "x" in D15
 
Upvote 0
I wrote this script:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("AA:AA")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim ans As String
Dim r As Long
r = Target.Row
ans = "Yes"
Dim Lastrow As Long
Lastrow = Sheets("Preapprovals").Cells(Rows.Count, "AA").End(xlUp).Row + 1
If Target.Value = ans Then Rows(r).Copy Sheets("Preapprovals").Rows(Lastrow)
End If
End Sub


But then the user said Sheet "Preapprovalas" had a table in it.

So I want to paste the row into the Tables 1st empty row.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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