+ Reply to Thread
Results 1 to 11 of 11

I Want to Link a Variable Range with Multiple Formulas

Hybrid View

  1. #1
    Registered User
    Join Date
    01-03-2022
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    24

    I Want to Link a Variable Range with Multiple Formulas

    Hi,
    Let me explain my issue

    Let, I have data in column F from Cell E4 to E18. Now I have to find five different values using formulas: Sum, Plus Count, Negative Count, Highest and Lowest (as you can see from the Attached Excel File)
    I have found all these values for the Range of E4 to E10 (E4:E10)

    My Requirement:
    I want to link Ranges of these 5 formulas with cells B4 and C4 (Cell B4 and C4 make basically a series staring and ending values)

    Now whenever I have to find these five values for a specific range, I would only put required series starting and ending values in cells B4 and C4 respectively)

    (Excel file is attached for further clarification)

  2. #2
    Registered User
    Join Date
    12-15-2021
    Location
    Seoul, South Korea
    MS-Off Ver
    Office 365
    Posts
    12

    Re: I Want to Link a Variable Range with Multiple Formulas

    Hi,
    You may apply like:

    Dim rng As Range
    Dim sn, en As Integer
    
    sn = Range("B4").Value
    en = sn + Range("C4").Value - 1
    set rng = Range("E" & sn:"E" & en)
    Range("G4").Application.Formula = "= SUM(rng)"
    ...
    Range("K4").Application.Formula = "= MIN(rng)"
    Good Luck !!!
    Last edited by AliGW; 01-10-2022 at 07:05 AM. Reason: Code tags added. Please read our rules as soon as possible!

  3. #3
    Registered User
    Join Date
    01-03-2022
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    24

    Re: I Want to Link a Variable Range with Multiple Formulas

    I tried your code but it does not work.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I Want to Link a Variable Range with Multiple Formulas

    Quote Originally Posted by John521520 View Post
    I tried your code but it does not work.
    That's a WORST response.

    How is it not working?

    see attached.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-03-2022
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    24

    Re: I Want to Link a Variable Range with Multiple Formulas

    Thanks a lot, it worked

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I Want to Link a Variable Range with Multiple Formulas

    Quote Originally Posted by John521520 View Post
    My Requirement:
    I want to link Ranges of these 5 formulas with cells B4 and C4 (Cell B4 and C4 make basically a series staring and ending values)

    Now whenever I have to find these five values for a specific range, I would only put required series starting and ending values in cells B4 and C4 respectively)
    Try
    vba
    Sub test()
        Dim r As Range
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "(\$?E\$?)\d+(:\$?E\$?)\d+"
            For Each r In [g4:k4]
                r.Formula = .Replace(r.Formula, "$1" & [b4] & "$2" & [c4])
            Next
        End With
    End Sub
    Or just
    1)Select G4:L4
    2) Ctrl + H (find + Replace) replace E4:E10 with OFFSET(INDIRECT("e"&$B$4&":e"&$C$4),,,$C$4-$B$4+1)
    Then the formula should work as you change any one of B4:C4.
    Last edited by jindon; 01-10-2022 at 06:03 AM.

  7. #7
    Registered User
    Join Date
    01-03-2022
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    24

    Re: I Want to Link a Variable Range with Multiple Formulas

    Hi,

    My issue remans unsolved. I tried your code but it does not work.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: I Want to Link a Variable Range with Multiple Formulas

    Administrative Note:

    @sungjunbae

    You need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code] [/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new here, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: I Want to Link a Variable Range with Multiple Formulas

    @John521520

    Please make it clear to whom you are responding in each case, as I have done in this post. Thanks.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: I Want to Link a Variable Range with Multiple Formulas

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

  11. #11
    Registered User
    Join Date
    12-15-2021
    Location
    Seoul, South Korea
    MS-Off Ver
    Office 365
    Posts
    12

    Re: I Want to Link a Variable Range with Multiple Formulas

    Thanks Ali,
    Hi John521520, please try below (previous I made mistake):

    Dim rng As Range
    Dim sn, en As Integer
    
    sn = Range("B4").Value
    en = sn + Range("C4").Value - 1
    set rng = Range("E" & sn:"E" & en)
    Range("G4").Value = Application.SUM(rng)
    ...
    Range("K4").Value = Application.MIN(rng)

+ 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. Autofill formulas with across multiple columns with variable range
    By jstan7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2015, 06:39 PM
  2. Copy Range of Formulas to a Variable Range of Cells
    By xace in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-07-2015, 10:28 PM
  3. Replies: 4
    Last Post: 06-27-2015, 09:43 AM
  4. Link macro to a button which will print a variable range.
    By Jmmybrdn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2012, 07:31 PM
  5. how to specify variable range in link?
    By 4mla1fn in forum Excel General
    Replies: 5
    Last Post: 07-13-2010, 11:15 AM
  6. Variable Range Names in Formulas
    By klindy in forum Excel General
    Replies: 1
    Last Post: 10-19-2006, 12:43 PM
  7. how to link the Table Range in Lookup function to a variable cells
    By daveexcel in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-22-2005, 05:14 PM

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