Finding last column & inserting

David2e

New Member
Joined
Sep 26, 2007
Messages
47
I have this working for rows in the same way I'm trying to get it to work for columns now, but I am getting an error and unsure what I've missed.

Code:
Summary.Select
FinalCol = Summary.Range("IV5").End(xlToLeft).Column - 2
Columns(FinalCol).Select
ActiveCell.EntireColumn.Select

vCols = Workings1.Cells(8, 3).Value
    
 Selection.Resize(columnsize:=2).Columns(2).EntireColumn. _
     Resize(columnsize:=vCols).Insert Shift:=xlToRight

    Selection.AutoFill Selection.Resize( _
     columnsize:=vCols + 1), xlFillDefault

    On Error Resume Next    'to handle no constants in range
    ' to remove the non-formulas
    Selection.Offset(1).Resize(vCols).EntireColumn. _
     SpecialCells(xlConstants).ClearContents

The vCols variable are the number columns to be inserted picked up from another cell storing this from user input (there are some other things before this macro is called).

The columns are to be inserted 2 columns to the left of the last column (sum column and a spacer column).

The error is showing on the line:
Code:
Selection.Resize(columnsize:=2).Columns(2).EntireColumn. _
     Resize(columnsize:=vCols).Insert Shift:=xlToRight

I must also admit, I did take the row insertion code, and tried to adapt it to columns, which mightn't quite be the right way to have gone about this.

Any help would be appreciated.

Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,216,158
Messages
6,129,207
Members
449,493
Latest member
JablesFTW

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