Relative number of list-row to reference in VBA?

Lil2606

Board Regular
Joined
Jan 29, 2019
Messages
79
Hi all,

I have 3 tables on a sheet and I'm trying to reference a ListRow.

I'm using .find to find an empty cell in the 3 tables and the row number - the ListRow number of that cell is what I would need.. but I get the actual row number and then Subscript out of range.. could someone help me with this please?

Here is the code:

Code:
[/COLOR]Sub try()

Dim i As Long
Dim ROFR As Range    'R_ow O_f F_ormula R_ange


For i = 1 To Sheet1.ListObjects.Count


Set ROFR = Sheet1.ListObjects(i).ListColumns("Something").DataBodyRange.Find(What:="", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)


If Not ROFR Is Nothing Then


'Here is the issue:


Sheet1.ListObjects(i).ListRows(ROFR.Row).Range(1, Sheet1.ListObjects(i).ListColumns("Something Else").Range.Column).Select


Exit Sub


End If


Next



End Sub[COLOR=#333333]

Its a very basic set-up.
I have 3 tables on Sheet4 the first table is 52rows + Headers in the 16th row. The second table is 24rows and starts in row70 with headers, the third table is 13rows and starts in row96 with its headers..

I need row 99 because it has the cell that I needed to find (ROFR) is in the 99th row, but if I write Sheet4.ListObjects(3).ListRow(ROFR.Row) I will get subscript out of range because ROFR.Row = 99 and my third table doesn't have 99 rows. It has 13rows (listrows). So I need the row number relative to the table not relative to the whole excel workbook.
 
Not sure to fully understand ... :wink:

If you need to Insert below your ActiveCell :

Code:
Selection.ListObject.ListRows.Add AlwaysInsert:= True

Hope this will help
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Code:
ActiveCell.Select
Selection.ListObject.ListRows.Add AlwaysInsert = True

Returns Subscript out of range
 
Last edited:
Upvote 0
Got it!!

Code:
Sheet4.ListObjects(ActiveCell.ListObject.Name).ListRows.Add (ActiveCell.Row - Sheet4.ListObjects(ActiveCell.ListObject.Name).HeaderRowRange.Row + 1)
 
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