Select Range (Last Row to Last Column)

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
Hi All! I am trying to insert a table to a selected range, but am running into an error. Below is the current code I am using:

Code:
Dim LRow As Long
Dim RngA As Range


'Create Table (Assignment_Data)

Application.ScreenUpdating = False

LRow = Cells(Rows.Count, 1).End(xlUp).Row
LCol = Cells(1, Columns.Count).End(xlToLeft).Column
RngA = Range(LRow, LCol).Select

 Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveSheet.ListObjects.Add(xlSrcRange, RngA, , xlYes).Name = _
        "Table1"

Thanks in advance!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You have a number of problems.

First, whenever you have an issue with a VBA error, always give the error number, error message, and what line of code it occurs on.

You should also show all of your code. Problems do not always originate where we think they do.

This line of code has multiple problems:
VBA Code:
RngA = Range(LRow, LCol).Select
You must use Set. You should not use Select. If you are specifying row and column you must use Cells instead of Range. Note that LRow and LCol will find the last used cell in column A and the last used cell in row 1. I would assume you do not want to overwrite existing data so I would add 1 to each of those for the table location. Replace with this:
VBA Code:
Set RngA = Cells(LRow + 1, LCol + 1)
 
Upvote 0
Thanks for your reply, but I am still getting an error starting with Set LRow. I totally blanked on using set.
Code:
Dim LCol As Long
Dim LRow As Long
Dim RngA As Range

'Create Table (Assignment_Data)
Application.ScreenUpdating = False

Set LRow = Cells(Rows.Count, 1).End(xlUp).Row  (ERROR HERE)
Set LCol = Cells(1, Columns.Count).End(xlToLeft).Column
Set RngA = Range(LRow, LCol)

 Application.CutCopyMode = False
 Application.CutCopyMode = False
 ActiveSheet.ListObjects.Add(xlSrcRange, RngA, , xlYes).Name = _
        "Table1"
 
Upvote 0
I did not suggest you do that. I suggested changing only one line of code, and you changed two other ones in addition.

You must use Set when assigning a Range to a Range variable. The other two are Long variables and you cannot use Set for those.
 
Upvote 0

Forum statistics

Threads
1,215,215
Messages
6,123,668
Members
449,114
Latest member
aides

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