Hi excelentuser,
I found this code at http://www.mvps.org/dmcritchie/excel/fillempt.htm that might do what you're looking for. I combined three pieces of code:
1. The code that fills empty cells with the text in the cell above it
2. The code to sort the selection by the name column (column A)
3. The code to remove those duplicate text entries created in step 1.
Prior to running the code you must select your range of data, e.g. A1:C47. Put this code in the worksheet's code module by right-clicking on the sheet tab and selecting View Code. You can then run the code by pressing ALT+F8 and selecting 'Sheet1.FillEmpty' from the list and clicking Run.
Sub Fill_Empty()
'--David McRitchie, 2003-07-24, fillempt.htm
'--Macro version of -- Excel -- Data Entry -- Fill Blank Cells
'http://www.contextures.com/xlDataEntry02.html
'http://www.pcworld.com/shared/printable_articles/0,1440,9346,00.html
Dim oRng As Range
Set oRng = Selection
Selection.Font.Bold = True
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Font.Bold = False
Selection.FormulaR1C1 = "=R[-1]C"
oRng.Copy
oRng.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Call clear_dupcells_below
End Sub
Sub clear_dupcells_below()
'D.McRitchie, 2006-02-01 www.mvps.org/dmcritchie/excel/fillempt.htm
Dim rng As Range, iRows As Long, iColumns As Long
Dim ic As Long, ir As Long
Set rng = Intersect(Selection, ActiveSheet.UsedRange)
Dim WithWhat As Variant
iRows = rng.Rows.Count
iColumns = rng.Columns.Count
If iRows < 2 Then Exit Sub
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For ic = iColumns To 1 Step -1
For ir = iRows To 2 Step -1
If rng.Item(ir, ic).Value = _
rng.Item(ir - 1, ic).Value Then
rng.Item(ir, ic).Formula = ""
End If
Next ir
Next ic
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
End Sub
Let us know how that works for you.
Bookmarks