简体   繁体   中英

Passing two arguments to a range

I have two arguments that are integer (xxddd and dimen) and want to pass them to cells as you can see in the below code but it doesn't work.

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
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

EDIT: re-reading your question I'm not sure why your original approach failed. Typically we try not to use Cells() without specifying a worksheet such as ws.Cells() , but in this case tagging .Address on the end of each argument should have resolved that...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM