将两个参数传递给范围

时间:2015-02-22 04:13:47

标签: excel vba excel-vba

我有两个整数(xxddd和dimen)的参数,并希望将它们传递给单元格,如下面的代码所示,但它不起作用。

Sub freind (xxddd, dimen)                        

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(3)
Dim rngA As Range


Set rngA = ws.Range(Cells(1, 1).Address, Cells(xxddd, dimen).Address)
end sub

1 个答案:

答案 0 :(得分:1)

Sub freind (xxddd, dimen)                        

    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets(3)
    Dim rngA As Range

    Set rngA = ws.Cells(1, 1).Resize(xxddd, dimen)
end sub

编辑:重新阅读您的问题我不确定您的原始方法失败的原因。我们通常会在未指定Cells()等工作表的情况下尝试不使用ws.Cells(),但在这种情况下,每个参数末尾的标记.Address应该已经解决了...