Solved

Set a  range to another worksheet using R1C1 format

Posted on 2016-08-12
4
53 Views
Last Modified: 2016-08-12
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
Comment
Question by:peispud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41754136
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
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 41754139
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
 

Author Closing Comment

by:peispud
ID: 41754169
Perfect!!    Thank all for helping.
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41754172
You're welcome. Glad to help.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question