Inserting Columns

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
I have the following code to insert columns, but for some reason it won't insert them. It doesn't give an error, the macro just stops and doesn't insert:

Sub Worksheet_S10()


'Activate Workbook
Workbooks("WorkBook.xlsm").Activate
'Activate Worksheet
Workbooks("Workbook.xlsm").Sheets("Sheet1").Activate


'Categorize as Insured or Uninsured
Dim lastRow As Long
lastRow = Range("E" & Rows.Count).End(xlDown).Row
Sheets("sheet1").Range("B10:B" & lastRow).Formula = "=IF(RC[7]>1,""Insured"",""Uninsured"")"


'Create Fiscal Year Based Off of Discharge Date
Sheets("Sheet1").Range("K10:K" & lastRow).Formula = "=YEAR(RC[-7])+(MONTH(RC[-7])>='FY Calculation'!R[-8]C[-10])"


'Insert Columns for Categorization
Workbooks("workbook.xlsm").Sheets("sheet1").Activate

[L9].Resize(, 3).EntireColumn.Insert


Thanks!







End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Why complicate things for inserting columns?

For this use simple code:
Code:
Columns(4).Insert Shift:=xlToRight
Just replace "4" with column number where you need a new one.

Tip: This adds new column to active worksheet. If you want it added in specified one it's better to refer to it:
Code:
Sheets("Sheet1").Columns(4).Insert Shift:=xlToRight
 
Last edited:
Upvote 0
Code:
[L9].Resize(, 3).EntireColumn.Insert
this works for me adding 3 extra columns after col K, on the active sheet.
An alternative would be
Code:
Columns(12).Resize(, 3).EntireColumn.Insert
 
Upvote 0
Not sure who you're talking to, but
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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