+ Reply to Thread
Results 1 to 5 of 5

Get Formula Range in a Cell

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Get Formula Range in a Cell

    Hello,

    Say I have a formula in A1 as

    Please Login or Register  to view this content.
    In Excel VBA, how can I extract those ranges? Which is

    A2:C100,B8,C10,A1-:B10,C1,C2,C3,C4,E10,E20,E30

    In the above case?

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Get Formula Range in a Cell

    Hi dluhut- This macro uses the DirectPrecedents method to extract the addresses of any cells the ActiveCell depends on.
    In this example, it just shows them in a msgbox.
    Please Login or Register  to view this content.
    NOTE: This approach has limitations. DirectPrecedents only finds cells on the ActiveSheet. Ranges on other Sheets are missed.
    Also, if a formula uses G1 and G2 separately, DirectPrecedents shows them as one range G1:G2.

    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee
    Last edited by leelnich; 05-26-2017 at 02:45 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Get Formula Range in a Cell

    Thanks leelnich!

    But when I change Range("A1") to Range("AQ398") for example, it didn't give me any result.

    FYI, Range("AQ398").Formula = SUMIFS($Z398:$AP398,$Z$5:$AP$5, AQ$5)

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Get Formula Range in a Cell

    I just updated the code (02:45 pm) to act on the currently selected cell ("ActiveCell"). Try that, and read the notes at the bottom. It's NOT perfect!

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Get Formula Range in a Cell

    Try this Userdefined Function.


    Use Formula "=ExtractRanges(A1)" where A1 is A string or a cell address

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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] Make data range in formula shift for a whole range when copying cell
    By Zaron in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-21-2016, 06:37 AM
  2. [SOLVED] if cell in range has formula equals cell in range on other worksheet
    By Little Guy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-25-2015, 03:38 PM
  3. Replies: 1
    Last Post: 03-02-2015, 11:18 AM
  4. Replies: 6
    Last Post: 06-05-2014, 05:02 PM
  5. [SOLVED] Formula to count frequency of data in cell range based on data in different cell range
    By jrosko1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-12-2013, 09:47 AM
  6. Replies: 1
    Last Post: 09-04-2013, 07:23 AM
  7. Inserting formula into cell/range refering to a range
    By CobertRannon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-30-2013, 01:28 PM

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