Set a range to another worksheet using R1C1 format


I am having problems getting this right.    Thank you for your help.

    Dim ws As Worksheet:  Set ws = Worksheets("MySheet")
    Dim CCC As Range
    Set CCC = Range(Cells(1, 1), Cells(1, 7))                       ' Seems OK
    Set CCC = Range(ws.Cells(1, 1), ws.Cells(1, 7))                 ' Computer gets angry

Open in new window

Who is Participating?
Subodh Tiwari (Neeraj)Connect With a Mentor Excel & VBA ExpertCommented:
Try this.....

Set CCC = ws.Range(ws.Cells(1, 1), ws.Cells(1, 7))

Open in new window

When you use only Set CCC = Range(Cells(1, 1), Cells(1, 7)), the range will be set according to the active sheet. While in the syntax above you qualified the cells reference with ws but not with Range so you also need to qualify the Range with the sheet reference, in this case ws.
Helen FeddemaCommented:
What worksheet are you using in line 3?  Is MySheet the current sheet, or something else?  The range depends on the worksheet, so the syntax would be like this:

   strRange = "A7:A10"
   Set rngPipeline = shtPipeline.Range(strRange)

Open in new window

peispudAuthor Commented:
Perfect!!    Thank all for helping.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome. Glad to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.