VBA - selecting [#This Row] in structured reference

GopherUK

Active Member
Joined
Jan 23, 2009
Messages
473
Hi,

Is it possible to create a structured reference in VBA that will point to the intersection of the current (active) row and a given column?

For example, in plain worksheet reference, it would be: =

=TableName[[#This Row],[COLUMNNAMEHERE]]

VBA doesnt seem to like the equivalent, which I believe would be: -

-----------------

Dim oSh As Worksheet

oSh.Range("TableName[[#This Row],[COLUMNNAMEHERE]]")

-----------------

If it will not accept this, is there any way to find out the row number relative to the table is? I could probably use a workaround from there.

Thanks.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Perhaps the "Intersect" method ?

Gary

Public Sub Test()

Dim oIntersect As Range
Dim oColumn As Range
Dim oRow As Range

Set oRow = ActiveCell.EntireRow
Set oColumn = ActiveSheet.Range("C:C")

Set oIntersect = Application.Intersect(oRow, oColumn)

oIntersect.Interior.ColorIndex = 3

End Sub
 
Upvote 0
I got it working with the intersect afterall. Would seem cleaner to do it with '#This Row' but it's working anyway. However, if anyone knows if it can be done with '#This Row', please let me know.
 
Upvote 0
Code:
    Dim r As Range
    
    Set r = Evaluate("TableName[[#This Row], [ColName]]")
 
Upvote 0
what about

cells(activecell.row,"C")

That way, if you really did need to have the column name as a string, it'll work.

Having said that, looking at everyone else's answer, perhaps I've missed something.
 
Upvote 0
Noticed when I pasted the below formula in a cell in Excel 2010, it auto replaced [#This Row] with @:
Code:
=COUNTIF(tblInput[[#This Row],[Col1]:[Col2]],C$1)
All special item specifiers except [#This Row] appear to work with Range:
Code:
Sheets("Input").Select
Range("A1:B1").Select
Range("tblInput[[Col1]:[Col2]]").Select
Range("tblInput[[#Headers],[Col1]:[Col2]]").Select
Range("tblInput[[#Headers],[#Data],[Col1]:[Col2]]").Select
[#This Row] causes: Run-time error '1004': Method 'Range' of object '_Global' failed
Code:
Range("C2").Select
Range("tblInput[[#This Row],[Col1]:[Col2]]").Select
Range("tblInput[@[Col1]:[Col2]]").Select
It's interesting that [#This Row] is the only 'special item specifier' that causes the error using VBA's Range (however I'm only testing with Excel 2010).

Relevant Info:
* Table Special Item Specifiers (incl [#This Row]): http://office.microsoft.com/en-us/e...references-with-excel-tables-HA010155686.aspx
* @ used in place of [#This Row] in Office 2010: http://blogs.office.com/b/microsoft-excel/archive/2010/01/25/table-improvements-in-excel-2010.aspx
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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