1

举个简单的例子,我必须选择一列中的每 22 个单元格,直到找到一个空单元格。我需要能够将所有这些单元格复制到剪贴板以粘贴到另一个电子表格中。我可以正确选择每个单元格,但不知道如何将它们收集到一个要复制的对象中。

盯着看的评论需要代码。

子 SelectAllValidCells()

  ' select first cell

  [J15].Select

  ' Test contents of active cell; if active cell is empty, exit loop.

  Do Until IsEmpty(ActiveCell)

     ' ***** need to figure out how to gather the valid cells 
     ' here to later copy to clipboard when we reach empty cell 

     ' Step down 22 rows to the next cell.
     ActiveCell.Offset(22, 0).Select

    ' Return to top of loop.
  Loop
  '***** copy gathered cells to clipboard

结束子

4

1 回答 1

1
Sub Tester()

Dim rng As Range, c As Range

    Set c = Range("J15")

    Do
        If rng Is Nothing Then
            Set rng = c
        Else
            Set rng = Application.Union(rng, c)
        End If

        Set c = c.Offset(22, 0)
    Loop While Len(c.Value) > 0


    If Not rng Is Nothing Then
        rng.Copy Range("K1")
    End If

End Sub
于 2012-11-20T23:53:28.053 回答