答案 0 :(得分:1)
Option Explicit
Sub compileData()
Dim a As Long, c As Long, r As Long, lc As Long
Dim brng As Range, arr As Variant
With Worksheets("sheet4")
Set brng = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A") _
.End(xlUp)).SpecialCells(xlCellTypeBlanks)
lc = .Cells.Find(What:="*", SearchDirection:=xlPrevious, _
After:=.Cells(1), SearchOrder:=xlByColumns).Column
For a = 1 To brng.Areas.Count
arr = brng.Areas(a).Offset(1, 0).Resize(3, lc).Value
For c = 2 To lc
If IsEmpty(arr(1, c)) Then
If Not IsEmpty(arr(2, c)) Then
arr(1, c) = arr(2, c)
ElseIf Not IsEmpty(arr(3, c)) Then
arr(1, c) = arr(3, c)
Else
arr(1, c) = "UNK"
End If
End If
Next c
brng.Areas(a).Offset(1, 0).Resize(1, lc) = arr
Next a
brng.EntireRow.Delete
.Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp)).Resize(, lc) _
.RemoveDuplicates Columns:=1, Header:=xlYes
End With
End Sub