View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
joemeshuggah joemeshuggah is offline
external usenet poster
 
Posts: 96
Default inserting columsns variable range

Thanks...this appears to be adding rows, however...

"ker_01" wrote:

As you insert each column, you move the remaining columns to the right, so
your total count is no longer accurate.

Try looping through from right to left instead of left to right; that way
your extra columns won't affect the "unprocessed" portion of your worksheet:

For i = LC to 2 step -1
'your code

HTH,
Keith

"joemeshuggah" wrote:

hello all,

i have a spreadsheet that is variable in range (number of columns can vary).
i would like to create a macro that for each column in the worksheet, two
new columns would be inserted to the left.

i thought this would work, but i am running into problems...

LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

LC = LastColumn

For i = 2 To LC
If Cells(5, i + 1) < "" Then
Cells(5, i).Select
Selection.EntireColumn.Insert
Selection.EntireColumn.Insert
End If
Next i

how do i go about accomplishing this?

thanks!