View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default macro or function help needed for adding columns for values missin

If it ends at 142 and is only in AF, possibly others are missing also. This
code will start at D1 (next to C1) and check to see if value in current cell
is 1 greater than in cell to its left. If not, then will insert a column and
put in the proper value. Continues until it hits an empty cell in row 1. In
the end you will have the entire sequence C1=101 ... AR1 = 142

Sub InsertColumnsAndValues()
'must be on sheet with data before running
'must be no empty cells in row 1 from
'start of series at C1 to end of series (AF1?)
'
'Practice with copy of your worksheet first!
'
Range("D1").Select ' not a mistake!
Do While Not (IsEmpty(ActiveCell))
If ActiveCell.Value < ActiveCell.Offset(0, -1) + 1 Then
Selection.EntireColumn.Insert
ActiveCell.Value = ActiveCell.Offset(0, -1) + 1
End If
ActiveCell.Offset(0, 1).Activate
Loop
End Sub

"Arain" wrote:

I have a sheet where the C1 has value 101 and goes to AF till 142. Its
missing values in between like 112 and 117. I want to add the column for the
missing value in that sheet. can someone please help. thanks.