Refering to table elements using column names

I've got two tables - dRow and dRowSetup.  Each comprises 2 columns named Lower and Upper.

I'm trying to use the following construct:

For Rw = 1 To Range("dRowSetup").Rows.Count
         If Range("dRowSetup[Lower]")(rw).Value = "" Then Exit For
         MsgBox Range("dRowSetup[Lower]")(Rw)
         Range("dRow[Lower]")(Rw) = Range("dRowSetup[Lower]")(Rw)
         Range("dRow[Upper]")(Rw) = Range("dRowSetup[Upper]")(Rw)
        .Range("AA1").Value = Rw
Next Rw

I keep getting: Method 'Range' of object '_Worksheet' failed

Range("dRowSetup").Rows.Count resolves correctly to 20, but things bomb out on the IF statement, or if removed, the MSGBOX.

any idea what I'm doing

March 26th, 2015 9:33am

Nothing wrong with your code - myabe it is your header not really "Lower"? Are both tables on the activesheet? Did you actually create a structured table, or just a named range?

Sub test()
Dim r As Range
For Each r In Worksheets("SheetName").Range("dRowSetup[#Headers]")
MsgBox """" & r.Value & """"
Next r
End Sub





Free Windows Admin Tool Kit Click here and download it now
March 26th, 2015 9:57am

Ah - user error.  I had "dRow" as a name, but it refered to Table1[#All].  Once I got rid of the reference and renamed the table itself to dRow, things starte
March 26th, 2015 10:05am

Those are the best errors - the ones that can be solved!
Free Windows Admin Tool Kit Click here and download it now
March 26th, 2015 10:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics