'Run-time error '1004' Insert method of Range class failed while adding column

It seems pretty easy, but not able to find workaround.

Excel 2010. Aim: adding 22 empty columns starting from B

Error: Run-time error '1004': Insert method of Range class failed

Code:

  Application.DisplayAlerts = False 
  Application.ScreenUpdating = False 
  Sheets(1).Select
  ActiveSheet.Tab.ColorIndex = xlColorIndexNone

  Dim WbPresent As Workbook
  Set WbPresent = ActiveWorkbook

  Dim FileData As String
  FileData = "160125"

  Dim TabName As String
  TabName = "IB Hire Plan - Hierarchy " & FileData


   Workbooks.Open Filename:= _
     "\\chca6030.eur.beluni.net\m137557$\Documents\Makro   VBA\ATR\Taleo\*.xlsm"
   Sheets("IB Hire Plan - Hierarchy").Select
   Sheets(3).Activate

  Sheets("IB Hire Plan - Hierarchy").Copy Before:=WbPresent.Sheets(1)
  Sheets("IB Hire Plan - Hierarchy").Select

  For colx = 2 To 23
  Columns(colx).Insert Shift:=xlToRight
  Next*

Was checking similar question, but did not find the good answer for that.



Solution 1:[1]

You haven't referenced the worksheet you wish to insert the columns in

Columns(colx).Insert Shift:=xlToRight

should be

ws.Columns(colx).Insert Shift:=xlToRight

where ws is the work sheet reference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 amiles