VBA - Tables - Select a cell in last row of Data Body Range

Marty Plante

New Member
Joined
Dec 28, 2016
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I'm struggling to find code that takes me to the last row in a table, in a particular column. I use a table for navigation with hyperlinks and when a new component in the workbook is created a row is added to the bottom of an existing table. I want to paste into one particular cell the name of the new item in the workbook. Finding last used row normally isn't a challenge but with tables I'm getting last row with data (don't care) and I want only the last row that code already created. New row - select cell in column X. A few links or advice would be helpful. Thank you!
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,679
Office Version
  1. 365
Platform
  1. Windows
Can you post the code you currently have.
 

Marty Plante

New Member
Joined
Dec 28, 2016
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Public Sub Add_Meal_To_Navigation_Table()

'This is called from another macro. Adds a new row to bottom of table. I would like to select the last cell in the 6th column of the table.

Sheet9.Select

ActiveSheet.ListObjects("Tbl_Navigation_Links").ListRows.Add AlwaysInsert:=True



End Sub
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,414
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Maybe you can adapt something like this.
VBA Code:
Sub test()
Dim LO As ListObject, LR As Long, LC As Long
Set LO = ActiveSheet.ListObjects(" Tbl_Navigation_Links ")
With LO
    LR = .Range.Rows.Count
    LC = .Range.Columns.Count
    'select the last row in the table
    .Range.Rows(LR).Select
    'select cell at the intersection of the last row and 6th column in the table
    .Range.Cells(LR, 6).Select
End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,679
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Ok, how about
VBA Code:
Sub MartyPlante()
   Dim NewRw As ListRow
   Set NewRw = Sheet9.ListObjects("Tbl_Navigation_Links").ListRows.Add(AlwaysInsert:=True)
   NewRw.Range(1, 6).Value = "Abc"
End Sub
 

Marty Plante

New Member
Joined
Dec 28, 2016
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Second one gets me there. First one put me on the totals row, sub martyplante works so I can continue build from here. Thanks for the assistance!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,679
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,842
Messages
5,627,203
Members
416,229
Latest member
mohammadmihdi

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
Top