resize method

T

Tim McPhillips

I have written the following code and I keep getting a run
time error 1004. Can anyone help?

Sub ResizeIT()

Dim range1 As Range
Dim range2 As Range
Set range1 = Worksheets("UnitTemplate").Range("CS7")
Set range2 = range1
Range("range1").Resize(, 3).Select
Selection.EntireColumn.Insert

End Sub

I am just trying to insert some columns based on a set
range address.

Tim McPhillips
 
C

Chip Pearson

Tim,

Is the UnitTemplate sheet active when you try to Resize and Select
the range? You can only select cells on the active sheet. Use

Worksheets("UnitTemplate").Activate

to activate the sheet before doing the Select.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
D

Dick Kusleika

Tim

Use

range1.Resize(,3).EntireColumn.Insert

Range("range1") doesn't work because Excel is looking for a named range
called range1. Since you've dimmed it as a range, you can use it as above.
 
T

Trevor Shuttleworth

Tim

Sub ResizeIT()

Dim range1 As Range
Dim range2 As Range
Set range1 = Worksheets("UnitTemplate").Range("CS7")
Set range2 = range1
range1.Resize(, 3).Select
Selection.EntireColumn.Insert

End Sub

Regards

Trevor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top