vba 将单元格从一张纸复制到另一张纸,对范围内的所有单元格重复

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19316346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:46:52  来源:igfitidea点击:

Copy cell from one sheet to another, repeat for all cells within range

excelvba

提问by user2870648

I need to repeat the code below for cells in the range A2 to A46 that contain values.

我需要为 A2 到 A46 范围内包含值的单元格重复以下代码。

Worksheets("Full Qual").Range("A2").Copy _
  Destination:=Worksheets("Test").Range("D4")
ActiveWorkbook.PrintOut From:=2, To:=4, Copies:=1, Collate:=True, _
    IgnorePrintAreas:=False

The goal is to copy the cell from worksheet "Full Qual" to worksheet "Test", print it, then move on to the next cell below and repeat for all cells with values up to cell A46.

目标是将单元格从工作表“Full Qual”复制到工作表“Test”,打印它,然后移动到下面的下一个单元格并重复所有单元格的值直到单元格 A46。

回答by Gary's Student

Consider:

考虑:

Dim N As Long, v As Range
For N = 2 To 46
    Set v = Worksheets("Full Qual").Range("A" & N)
    If v.Value <> "" Then
        Worksheets("Full Qual").Range("A" & N).Copy _
          Destination:=Worksheets("Test").Range("D4")
        ActiveWorkbook.PrintOut From:=2, to:=4, Copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
    End If
Next N

UNTESTED

未经测试