Problems with Selection.Resize ... Error 1004

billyheanue

Board Regular
Joined
Jul 13, 2015
Messages
109
Hi all, so I am trying to resize the selection to equal a number of rows and columns specified in cells C45 and C46, respectively. My code gives me a 1004 Object Orientated error. Does anyone know how to fix this?



Sub TableExpand()


Worksheets("Sheet1").Activate
numrows = Selection.Rows.Count
numColumns = Selection.Columns.Count
Selection.resize(numrows = "C45", numColumns = "C46").Select


End Sub


I know there are probably a million things wrong with this, and if anyone has any help, it would be greatly appreiciated!

Thanks!
Bill from Mass
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Not sure why you are calculating the number of row and columns in your selection if you aren't using it for anything.

If you want code that will resize whatever is currently selected on Sheet1 based on the values in C45 and C46, you could do that like this:
Code:
Worksheets("Sheet1").Activate
Selection.Resize(Range("C45"), Range("C46")).Select
 
Upvote 0
Thanks! I am very new to using VBA. I am trying to expand a table.

I didn't know how to refer to values in cells for instructions on how big to expand a table.

For instance, on "Sheet 2" I have:
Macro Information
Start ColumnP
# Rows:4
End Row:40

<tbody>
</tbody>

P is where to insert another column (where to insert changes all the time), and "4" is how many rows long the table already is. For this instance, the existing table ends at column O (with P being the first blank column), starts at row 37, and ends at row 40. I just want to resize the table one more column, based on whatever the instructions are above. This is all on Sheet 1, and the info ("Macro Information") comes from Sheet 2.

Thanks for your help so far!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,548
Messages
6,125,472
Members
449,231
Latest member
Sham Yousaf

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