Select last used Row in Table

AndyEd

Board Regular
Joined
May 13, 2020
Messages
124
Office Version
  1. 365
Platform
  1. Windows
I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which require the Row to expand to fit.

Due to everything being locked down the user cannot manually adjust the Row height or via the Autofit function. A VBA enabled button allows the user to create new Rows as required.

I've managed to incorporate code to Autofit the Row height, as long as the user stays within the last Row prior to hitting the button. If they tab across fine, however if they hit <Enter> and move down a Row (out of the Table and into the sheet) or click anywhere else, the new Row is adjusted only. All the functionality is then locked out, as is necessary.

Can someone advise how I can ensure a cell in the last Row containing information is selected?

Thanks,
 
Maybe...

VBA Code:
j = Range(loTable).Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row
Rows(j).AutoFit
Application.Goto Cells(j + 1, Range(loTable).Columns(1).Column)
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I've figured it out now, using

Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
 
Upvote 0
I've figured it out now, using

Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select

Put any text in a cell in column A below the table. Do you still get the result that you want?
 
Upvote 0
Hi MARK828

You are of course correct, it doesn't work.

I'm not sure I understand enough though, hence I'm getting the following message when running the code,

Method 'Range'of object'_Global' failed.

???
 
Upvote 0
The following line is highlighted.

VBA Code:
j = Range(loTable).Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row
 
Upvote 0
The only way that would come up is if it isn't seeing the range. It works fine for me.
See the workbook in the link below.
The only thing that I have done is qualify the ranges for extra cover in case you run it from another sheet and commented out the sheet protection.
There is a button on Sheet1 that runs the macro.

 
Upvote 0
This is now showing the following error,

Runtime Error 91: Object variable or with block variable not set

I've checked other posts etc. but can't figure out why.
 
Upvote 0
On the same line,

VBA Code:
j = oSheetName.Range(loTable).Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row
 
Upvote 0
If you are running the code on the workbook that I posted then I can't answer that as the workbook that I posted works on my computer.
If you are running the code in the workbook on your original workbook are you sure that you turned the protection off on the sheet if you are running the code as I stated
The only thing that I have done is qualify the ranges for extra cover in case you run it from another sheet and commented out the sheet protection.
or have you declared j as a range rather than a long?
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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