View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
excel-ant excel-ant is offline
external usenet poster
 
Posts: 26
Default Inserting Columns based on missing headers


Hi Dow,

In the following example I've set up a For Next loop to work from left
to right, checking for the appropriate header of X1,X2...X10. If
missing a column is inserted and the header updated as required.

Sub Dow()

' We expect 10 column headers X1 to X10. if one is missing we
insert a column

For i = 1 To 10
If Cells(1, i) < "X" & i Then
Cells(1, i).EntireColumn.Insert
Cells(1, i) = "X" & i
End If
Next

End Sub

Hopefully this works as you require.

Anthony