我正在尝试将包含空白单元格的范围复制并粘贴到另一张纸上的单个列中。我希望忽略这些空白。
这是我现在使用的Frankenstein代码,它很慢而且有点笨拙picture included to better describe
我想扩展它,以便多个范围可以粘贴到同一列中,即找到具有值的最后一个单元格并粘贴到下一个单元格中。
我被告知应该看起来像这样
'for r = 1 to 4
' for c = 1 to 8
' does rc have val,
' then copy to new sheet
' increment copy var
' increment c
' increment r
Sheets(Array("next record date")).Select
Range("G11:AZZ110").Select
If TypeName(Selection) = "Range" Then
If Selection.Count > 1 Then
If Selection.Count <= Selection.Parent.Rows.Count Then
vaCells = Selection.Value
ReDim vOutput(1 To UBound(vaCells, 1) * UBound(vaCells, 2), 1 To 1)
For j = LBound(vaCells, 2) To UBound(vaCells, 2)
For i = LBound(vaCells, 1) To UBound(vaCells, 1)
If Len(vaCells(i, j)) > 0 Then
lRow = lRow + 1
Sheets("Data").Select
Range("E2").Select
vOutput(lRow, 1) = vaCells(i, j)
Else
End If
Next i
Next j
Selection.ClearContents
Selection.Cells(1).Resize(lRow).Value = vOutput
End If
End If
结束如果
谢谢,
杰罗姆
答案 0 :(得分:0)
特殊单元常量方法和粘贴转置
Public Sub TransposeRange()
ThisWorkbook.Worksheets("next record date").Range("G11:AZ11").SpecialCells(xlCellTypeConstants, 23).Copy
ThisWorkbook.Worksheets("Data").Range("E2").PasteSpecial Paste:=xlValues, Transpose:=True
End Sub