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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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:
[TABLE="width: 192"]
<tbody>[TR]
[TD="class: xl81, width: 128, colspan: 2"]Macro Information[/TD]
[TD="class: xl75, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl77, colspan: 2"]Start Column[/TD]
[TD="class: xl74"]P[/TD]
[/TR]
[TR]
[TD="class: xl77, colspan: 2"]# Rows:[/TD]
[TD="class: xl74, align: right"]4[/TD]
[/TR]
[TR]
[TD="class: xl79, colspan: 2"]End Row:[/TD]
[TD="class: xl76, align: right"]40[/TD]
[/TR]
</tbody>[/TABLE]

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,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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