+ Reply to Thread
Results 1 to 14 of 14

Using Range to refer to cells

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Using Range to refer to cells

    I'm a bit confused. I have a custom function that works perfectly when I use the following to set the range I'm working with.

    Please Login or Register  to view this content.
    As part of an ongoing development I'd like to be able to pass the name of the range in the function, but before I get there I needed to make sure I had the syntax right for changing the specfic range above to a set of named cells. The cells above are called "Table_0" and this applies from anywhere in the workbook, so why does the following code not seem to work?

    Please Login or Register  to view this content.
    Rather than an answer it just gives me a #VALUE error. WHat am I missing?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using Range to refer to cells

    Have you tried this?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Using Range to refer to cells

    Do you mean you need the address of the sheet name within the rng address?
    Try this code (May help you)
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Using Range to refer to cells

    Well that was staring me in the face! That works perfectly. Thanks. Even managed to butcher it to take the range as a variable- which it turns out was a lot easier! If there are two workbooks open with the same named range does that cause an issue? Or will it always just look at the activeworkbook?

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Using Range to refer to cells

    Try this in that case
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Using Range to refer to cells

    Does that mean it will look for the same table in another workbook? If so is it as simple as changing it to false to stop it looking?

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using Range to refer to cells

    Are you actually referring to a table?

    If you are then you could use the ListObjects collection of the sheet it's on to refer to it.

  8. #8
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Using Range to refer to cells

    It's a table - from external data. Works as is simply enough thankfully. If I could avoid getting sheet specific that would be great (needs replicated across 40+ different workbooks). The joys!

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using Range to refer to cells

    Where will the code that refers to the table be located?

  10. #10
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Using Range to refer to cells

    In a VBA module in each of the workbooks. As I don't have control over where each one ends up (or how many copies) it's about the best I can come up with.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using Range to refer to cells

    Within a module in a workbook you can use ThisWorkbook to refer to the actual workbook the code/module is in.

  12. #12
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Using Range to refer to cells

    So I can simply make it "thisWorkbook.range("name here")" ? COulnd't get it going with thisworkbook before - but that's when I couldn't get it going at all of course!

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using Range to refer to cells

    Unfortunately you can't use ThisWorkbook.Range.

    What exactly are you dealing with?

    How many sheets do the workbooks you are working with have?

    How many tables in each workbook?

  14. #14
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Using Range to refer to cells

    That would answer why I had a problem then.

    It may not be an issue but I can see a case where someone ahs 2 workbooks open at the same time. IN theory they will be looking at the same info regardless of which table they look at.

    The workbooks differ in size. Some with one or two sheets some with about 20. Most will only have 1 table (and this should be the same table coming from the same external data) but one or two wil have secondary tables (which will have different names).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Fix range in formula and range refer to other sheet
    By DavidRoger in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-22-2012, 11:51 AM
  2. [SOLVED] Getting an error when refer to a Range with the .Cells method
    By mgaworecki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2012, 11:39 AM
  3. Refer to cells in the range consisting of non-adjacent cells
    By dmitry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2011, 10:48 AM
  4. Replies: 5
    Last Post: 11-13-2006, 10:42 AM
  5. [SOLVED] copy/paste won't refer to the appropriate range of cells
    By debandstormy in forum Excel General
    Replies: 0
    Last Post: 08-15-2006, 12:50 PM
  6. Refer to rows in a range
    By ewan7279 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2006, 12:25 PM
  7. [SOLVED] Can a cell refer to a Range of cells?
    By Courreges in forum Excel General
    Replies: 3
    Last Post: 06-13-2006, 10:30 AM
  8. [SOLVED] How do I refer a Range to a Cell
    By Mal in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-07-2005, 04:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1