首页 > 解决方案 > 我想将非空白单元格和相应的标题复制到所需目的地的另一张纸上

问题描述

从下面提到的代码中,我需要一个类似output选项卡的输出:

Sub Macro1()
Dim rngMyCell As Range
Dim wsInputTab As Worksheet
Dim wsOutputTab As Worksheet

Application.ScreenUpdating = False

Set wsInputTab = Sheets("Input") 'Name of input sheet. Change to suit if necessary.
Set wsOutputTab = Sheets("Output") 'Name of output sheet. Change to suit if necessary.

For Each rngMyCell In wsInputTab.Range("A3:A" & wsInputTab.Cells(Rows.Count, "A").End(xlUp).Row)
    If IsError(rngMyCell) = False Then
        If Len(rngMyCell) > 0 Then
                wsOutputTab.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = rngMyCell

        End If
    End If
Next rngMyCell

Set wsInputTab = Nothing
Set wsOutputTab = Nothing

Application.ScreenUpdating = True

MsgBox "Done."

End Sub

标签: excelvba

解决方案


推荐阅读