0

我有一个从 A 列到 F 列的动态长度列表。(从第 1 行开始)我需要编写一个代码来将此列表打印在弹出窗口中。我不希望它打印在另一张纸上,这个列表所在的这张纸非常隐藏。我需要尽量减少复制这些数字,因此我不希望它在另一张纸上。

正如我所说,问题是这个列表是动态长度的。所以我会有类似的东西:

msgbox(upf.cells(1,1) & " " & upf.cells(1,2) & " " & upf.cells(1,3) & " " & upf.cells(1,4) _
       upf.cells(2,1) & " " & upf.cells(2,2) & " " & upf.cells(2,3) & " " & upf.cells(2,4) _
       ... up to row lr)

我怎样才能在某种 for i=1 to lr 循环中写这个?

谢谢!

4

1 回答 1

0

作为一个基本的例子......

Sub tgr()

    Dim upf As Range
    Dim cIndex As Long
    Dim rIndex As Long
    Dim sMsg As String

    Set upf = Range("A1", Cells(Rows.Count, "F").End(xlUp))

    For rIndex = 1 To upf.Rows.Count
        For cIndex = 1 To upf.Columns.Count
            sMsg = sMsg & " " & upf.Cells(rIndex, cIndex)
        Next cIndex
    Next rIndex

    MsgBox Mid(sMsg, 2)

End Sub
于 2013-10-08T22:59:51.323 回答