View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dow Dow is offline
external usenet poster
 
Posts: 31
Default Inserting Columns based on missing headers

On May 14, 1:13*pm, excel-ant wrote:
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


That is really cool, Anthony. I can see some places where I will be
able to use this concept.

I see now that I should not have used somethng as easy as X1, X2 for
the example of my column headers.

The X1, X2, etc were examples. The actual headings are closer to
"advanced", "redo", "undo", "territories", "box 3". Nothing as nice
and simple as my example.

Do you know of a way to loop through a list of words like this in a
macro?

Dow.