Insert Columns based on cell value

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
 
M

mangesh_yadav

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top