描绘数据和基础Excel文件的图像
问题以及我尝试过的内容
答案 0 :(得分:2)
Sub DoIt()
Dim r1 As Range, r2 As Range, r3 As Range, cel As Range
With Worksheets("Sheet1") ' <-- your own sheet name here
Set r1 = .Range("B3", .Cells(.Rows.Count, "B").End(xlUp))
Set r2 = .Range("G3", .Cells(.Rows.Count, "J").End(xlUp))
Set r3 = .Cells(.Rows.Count, "L").End(xlUp).Offset(1)
For Each cel In r1
If Not IsEmpty(cel) Then
r3.Resize(1, 4).value = cel.Resize(1, 4).value
Set r3 = r3.Offset(1)
Else
r3.Resize(r2.Rows.Count, r2.Columns.Count).value = r2.value
Set r3 = r3.Offset(r2.Rows.Count)
End If
Next
End With
End Sub
答案 1 :(得分:0)
有几种方法可以解决您的尝试。如果你不得不重复做这两件事,你可以用VBA做什么
(这不会填充空隙,但会将它们聚合在一起,然后您可以轻松过滤或转动数据表)
如果你想以复杂的方式解决它,你将不得不
(这需要比方法1更多的思考和逻辑,但它会像你最初要求的那样填补空白)
这是让你入门的东西:
Application.ScreenUpdating = False
'set range limits
endRange1 = 17
endRange2 = 5
Dim rowArray() As Variant
'step 1
For i = 3 To endRange1
If Cells(i, 2).Value = "" Then
range1EmptyRow = range1EmptyRow + 1
ReDim Preserve rowArray(1 To UBound(rowArray) + 1) As Variant
rowArray(UBound(rowArray)) = i
End If
Next i
'step 2
For i = 3 To endRange2
If Cells(i, 7).Value <> "" Then range2Rows = range2Rows + 1
Next i