Retrieving specific cells via index on a Row

chickyguy

New Member
Joined
Mar 27, 2024
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
Hi all,

Silly question but this is so unintuitive for me:

VBA Code:
For Each Table in Doc.tables
    For Cnt=1 to Table.Rows.Count
        Row = Table.Rows(Cnt)
        If ...
            DataRow = Table.Rows(Cnt+1)
            MsgBox DataRow.Cells(2)
        End If
    Next Cnt
Next Table

I can do Table.Rows(Cnt) but apparently I'll get Run-time error 5941: requested member of the collection does not exist.

But I can certainly access the cells if I do:
Code:
For Each Table in Doc.tables
    For Cnt=1 to Table.Rows.Count
        Row = Table.Rows(Cnt)
        If ...
            DataRow = Table.Rows(Cnt+1)
            For Each Cel in DataRow.Cells
                MsgBox Cel
            Next Cel
        End If
    Next Cnt
Next Table

However, this is not the solution I'm looking for. I just need to retrieve the 3rd cell, which I do know exist cause it did print out 3 MsgBox...
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
There's no problem. I screwed up and forgotten that collections start at index 1 instead of 0.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,208
Members
452,618
Latest member
Tam84

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