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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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