我刚刚用您提供的数据测试了这段代码。根据工作表中的数据,应该很好。当然,如果数据范围发生变化,可能需要稍作调整。
Sub clean_data()
Dim wks As Worksheet
Dim cel As Range
Set wks = ThisWorkbook.Sheets("Imported Data")
With wks
'first bring columns F:G up to match their line
For Each cel In Intersect(.UsedRange, .UsedRange.Offset(1), .Columns(6))
If cel = vbNullString And cel.Offset(, -2) <> vbNullString Then
.Range(cel.Offset(1), cel.Offset(1, 1)).Copy cel
cel.Offset(1).EntireRow.Delete
End If
Next
'now fil columns A:D to match PO Date and PO#
For Each cel In Intersect(.UsedRange, .UsedRange.Offset(1), .Columns(1))
If cel = vbNullString And cel.Offset(, 5) <> vbNullString Then
.Range(cel.Offset(-1), cel.Offset(-1, 3)).Copy cel
End If
Next
End With
End Sub