Easier way to insert columns
Hi Sanj.
As another suggestion:
Sub TestIt2()
Dim i As Long, j As Long
Dim arr As Variant
arr = Array("Status", "Details", "Header3", "Header4", "Header5", _
"Header6", "Header7", "Header8", "Header9", "Header10", _
"Header11", "Header12", "Header13", "Header14", "Header15", _
"Header16", "Header17", "Header18", "Header19", "Header20") '... etc
For i = 1 To (UBound(arr) - LBound(arr) + 1) * 2 Step 2
j = j + 1
Columns(i).Insert
Columns(i).Cells(1).Value = arr(j - 1)
Next
End Sub
---
Regards,
Norman
"sanj" wrote in message
...
Hi,
I need to insert 40-50 columns and label the headers, at the moment I am
using the following code in a macro:
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "Status"
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
ActiveCell.FormulaR1C1 = "Details"
etc
Is there an easier way to write this?
Thanks!
Excel 2002
|