+ Reply to Thread
Results 1 to 14 of 14

Macro to adjust formula in a range

  1. #1
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Macro to adjust formula in a range

    Looking for VBA macro to adjust formula range based on row break. The main formula cover the entire range (=INDEX($AB$2:$AB$151,MATCH(U2,$Y$2:$Y$151,0))) for data; I then added a row break and would like it to automatically adjust for each row break instead of manually changing the formula as the datasets is huge. See sample data. Desired outcome is in column AG and AH. Formula without row break is in AD and AE.

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to adjust formula in a range

    Change all your formulae in columns AD and AE to look like this: =IFERROR(INDEX($AB$2:$AB$151,MATCH(U2,$Y$2:$Y$151,0)),"")
    Then select the range in column AD from row 2 to row 151. Next click on "Conditional Formatting" in the HOME tab in the top menu. Click "Use formula to determine which cells to format". Paste this formula in the "Format values ...." box: =AD2="" then click the "Format" button to select your color. Repeat the process for column AE and use this formula: =AE2=""
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Mumps1: The desired result result is not to color but apply VBA to update the formula to accurately adjust the formula for each range. Your approach did not work. Not looking to color the output results. Thanks.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Macro to adjust formula in a range

    try

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Andy Pope: works for my sample file. My original file Desired outcome is in column AH and Ai. Are you able to modify the code to cover AH and AI? Also, datasets is over 200,000 rows. Will this VBA code cover over 200, 000 rows? If no, please modify as well. Thanks.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Macro to adjust formula in a range

    It already locates the last row. There is a limit on the number of areas in a single block, but I can not tell whether your actual data will reach that limit. If it does you would need to alter the code to get 1 block at a time and modify the formula.

    Please Login or Register  to view this content.
    You just need to adjust the offset and relative reference.

  7. #7
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Andy Pope: I am getting Run Time Error 1004. Application-defined or object defined error. Any fix? Thanks.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Macro to adjust formula in a range

    Can you confirm the number of blocks of data you have.

    Or post a sanitised workbook that has the same layout.

  9. #9
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Andy Pope: Total data rows is 263,841 and column is A2:Ai263841. Desired outcome is in column AH2 and Ai263841 (similar to the line breaks in the sample file. Thanks
    Attached Files Attached Files
    Last edited by bjnockle; 08-13-2020 at 08:02 AM.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Macro to adjust formula in a range

    That does not tell me the number of areas in the data.

    And there is no need to PM me your reply

  11. #11
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Andy Pope: That does not tell me the number of areas in the data. See attached file. That is a sample copy of my original with limited data. And there is no need to PM me your reply - noted - I apologize. Thanks.
    Attached Files Attached Files
    Last edited by bjnockle; 08-13-2020 at 08:09 AM.

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Macro to adjust formula in a range

    Please Login or Register  to view this content.
    As it used specialcells to locate blocks of constants it failed as column AB in this data set has formula.

    And as the file still only contains ~150 records I can not say it will fail on your actual data

  13. #13
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Andy Pope: Code is running (due to large datasets). Did not give the error code this time around. Will update you. Thanks alot.

  14. #14
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Macro to adjust formula in a range

    Andy Pope: the code works like a charm. You are simply the best.

+ 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] Adjust email macro to send only select files in a folder rather than all ref'ed in a range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2016, 07:37 PM
  2. [SOLVED] automatically adjust range in formula?
    By hannez in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-02-2016, 08:40 AM
  3. [SOLVED] Run macro and adjust the column width range A:Y
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-03-2014, 12:16 PM
  4. Need to adjust a named range formula - Help Please!
    By john dalton in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-28-2014, 07:19 AM
  5. Array Formula should adjust to changing range
    By Shinga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2013, 05:38 AM
  6. Adjust formula range based on other cell values
    By Sardius in forum Excel General
    Replies: 4
    Last Post: 03-01-2012, 03:10 PM
  7. Macro to adjust the print range
    By ice in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2009, 08:32 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