View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default how to seperate cells with equal blank cells

How about another macro?

You could call it at the end of your Sub InsertRow_At_Change() macro.

Just add the line Fill_Blanks above End Sub in that macro.

End With

Fill_Blanks
End Sub


Sub Fill_Blanks()
'by Dave Peterson 2004-01-06
'fill blank cells in column with value above
Dim wks As Worksheet
Dim rng As Range
Dim LastRow As Long
Dim col As Long

Set wks = ActiveSheet
With wks
col = ActiveCell.Column
'or
'col = .range("b1").column

Set rng = .UsedRange 'try to reset the lastcell
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set rng = Nothing
On Error Resume Next
Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "No blanks found"
Exit Sub
Else
rng.NumberFormat = "General"
rng.FormulaR1C1 = "=R[-1]C"
End If

'replace formulas with values
With .Cells(1, col).EntireColumn
.Value = .Value
End With

End With

End Sub

On Thu, 10 May 2007 09:21:03 -0700, yaling
wrote:

Dear Gord Dibben,

Your solution is really helpful. You are so smart.

Can I ask you another question? After i got them separated, i need them to
repeat themselves in the blank rows below the company name? How can i do that?

Thanks a lot. Looking forward to your reply.

Yaling

"Gord Dibben" wrote:

yaling

Are you up for some VBA macro?

The following will insert a blank row at each change in value in Column A

Sub InsertRow_At_Change()
Dim i As Long
With Application
.Calculation = xlManual
.ScreenUpdating = False
End With
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
If Cells(i - 1, 1) < Cells(i, 1) Then _
Cells(i, 1).Resize(1, 1).EntireRow.Insert
'change .Resize(1, 1) to (2, 1) for two blank rows.
Next i
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With
End Sub


Gord Dibben MS Excel MVP

On Wed, 9 May 2007 16:50:01 -0700, yaling
wrote:

hello,

i have a company name list with thousands of companies. they are in one
colume and followed one by one. i need them to be seperated with equal blank
cells between each two companies. Is there any efficient way to get the job
done?

thanks,