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.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hello,

Understand you can find the Range ROFR ...

What is it exactly that you want to Select ... once you have found this empty range ...???
 
Upvote 0
Another cell in this same row, which's column is "Something Else" in this example.. In my real code I don't select it, in fact my active cell has a very important job so I can't change it, this was just for the sake of the example.
 
Upvote 0
OK ...

To get to another cell in the same row ... most probably you will need to use ROFR.Offset (0, number of columns )

number of columns is a positive or negative number to reach your Target cell ...

Hope this will help
 
Upvote 0
Everything is ... Relative ... ha ha ha :LOL:

Glad you could fix your problem ....

Thanks for your Thanks ...:)
 
Upvote 0
Ohh I was so happy about that, but I forgot, I have the same issue in another part of my code..

I have this:

Code:
Sheet4.ListObjects(ActiveCell.ListObject.Name).ListRows.Add (ActiveCell.Row)

which again.. returns the runtime error since I don't have 99 rows :(
 
Upvote 0
What exactly this instruction is supposed to produce ...??? :eek:
 
Upvote 0
It adds a row to the listobject which has the active cell in it, and depending on the last bracket it adds it to where I want it, so..

Lets say my active cell is A99 which is in my 3rd table Table3, this code translates to:

Code:
[COLOR=#333333]Sheet4.ListObjects(Table3).ListRows.Add (99)[/COLOR]

so the 99 is not right.. it should be 3.. cause its my 3rd listrow in the table..

if it would be

Code:
[COLOR=#333333]Sheet4.ListObjects(Table3).ListRows.Add (3)[/COLOR]

then this row would be an empty row in the "3rd position" so this would be my new 3rd row in the table.
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,343
Members
449,219
Latest member
Smiqer

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