Selecting cells on 2007 tables with vba

latecnik

New Member
Joined
Sep 17, 2009
Messages
5
Hello there!,

I´m trying to use VBA to select and manipulate one cell of the active row of the current table using Excel 2007 terminology, (in order to change its value), something like this:

Application.Range("PAYMENTS[[#This Row],[LASTNAME]]").Value = "Smith"

where the table is PAYMENTS and the field is LASTNAME,

However, this way will generate runtime errors and won´t seem to work...

The only way I´ve found to achieve it is to go there (to the cell) and then change the selection´s value, like this, (which looks inefficient and time consuming to me):

Application.Goto Reference:="PAYMENTS[[#This Row],[LASTNAME]]"
Selection.Value = "Smith"

Do you know how to achive that manipulation with more efficient VBA instructions?

Thank you very much in advance for your help!

LaTecniK
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I have a certain amount of personal distaste for Excel's new table referencing system but in a quick check it doesn't seem to have made its way into Visual Basic as far as I can tell. So the syntax of range("Table[[row][column]]") seems to be a problem.

To answer your question though, if you have a range and a row and column number, you can reference it by .cell(row,col). So if your table is indeed named "Table", it would look something like:

.range("Table").cells(r,c)="Some value" or perhaps .range("$A$2:$D500").cells(r,c)

Note that the r,c are relative to the current table; they are not the absolute row and column. If you want to do it that way, then obviously that would be

activesheet.cells(r,c)

You can use .["Table"].cells(r,c) = "Some value" if you are using named ranges.

In general, it's best to place the value in the cell without selecting the cell first. Each action actually affecting the sheet really slows things down so 1 action is better than the 2 required with select.
 
Upvote 0
In a Standard Module enter:

Code:
Sub EnterName()  'Use/Assign Short_Cut_Key  Ctrl+Shift+E
Dim V As String
V = "Smith"
Sheets("Payments").Cells(ActiveCell.Row, 7) = V  'Lastname is Column G
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,384
Messages
6,119,201
Members
448,874
Latest member
Lancelots

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