• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 65
  • Last Modified:

Set a range to another worksheet using R1C1 format

Hi.

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

0
peispud
Asked:
peispud
  • 2
1 Solution
 
Subodh Tiwari (Neeraj)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.
0
 
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)
   rngPipeline.Select

Open in new window

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now