Insert Columns based on cell value

  • Thread starter Thread starter Jill
  • Start date Start date
J

Jill

Hello!
Could you please tell me how (in a macro) to insert
multiple blank columns based on the value of a cell.
Example: if A1=2, then insert 2 columns...a new B & C
column. Example: If D1=4, then insert 4 columns...a new
E, F, G & H column.
Your help would really be appreciated.
Thank you,
Jill
 
put the foolwoing code in the worksheet module

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Row = 1 And IsNumeric(Target.Value) Then
If Target.Value > 0 Then
Range(Cells(1, Target.Column + 1).Address, Cells(1,
Target.Column + Target.Value).Address).EntireColumn.Insert
End If
End If

End Sub


- Mangesh
 
Back
Top