+ Reply to Thread
Results 1 to 6 of 6

Turn formula into macro

  1. #1
    Registered User
    Join Date
    05-11-2016
    Location
    Dallas
    MS-Off Ver
    2016
    Posts
    8

    Turn formula into macro

    My goal is for a macro to automatically select the range of cells below Door Size and Qty in this formula.

    =SUM(E2:E5)+SUMPRODUCT((LEFT(D2:D5,1)="(")*(E2:E5))

    Where E2:E5 represents the full range of numbers below "Qty" and D2:D5 represents the full range of numbers below "Door Size".

    The order of columns and number of rows is subject to change so the macro should automatically find "Door Size" and "Qty", select the range of numbers below, and apply these ranges to the above formula. The purpose of the formula is to double the quantity of doors at pairs, where the door size starts with a "(".

    I have a similar macro that finds "Door Size" and highlights the entire column, but I need the macro to only select the range underneath "Door Size" and stop once it hits a blank. And then do the same thing for "Qty" and insert those ranges into the formula above.

    Here's the macro to highlight the door size column.

    Please Login or Register  to view this content.
    Any help would be greatly appreciated!
    Attached Files Attached Files
    Last edited by jeffreybrown; 09-28-2018 at 11:08 AM. Reason: Please use code tags!

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

    Re: Turn formula into macro

    Please Login or Register  to view this content.

    This Version will run whenever you make a change on the sheet.

    Right Click on the sheet name at the bottom of excel and select view code.

    Paste the code in the module that opens and then close it.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 09-28-2018 at 06:22 PM.
    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.

  3. #3
    Registered User
    Join Date
    05-11-2016
    Location
    Dallas
    MS-Off Ver
    2016
    Posts
    8

    Re: Turn formula into macro

    Thank you for the response! I've slightly adjusted the macro so that it will fit more ranges of data. The column headers aren't always in the first row so I changed the range to 1:15 (the headers are seldom if ever below row 15) and this worked. However, I'm hoping you can help me refine the formula. Instead of R2C, I'd like the "2" to automatically be the row below the header.

    I store my macros in a hidden PERSONAL Excel Binary Workbook in the XLSTART folder so that the few macros I run are always available in every new workbook. I think I can store this Macro in that same workbook and then if the range changes I'll just re-run the the macro which would eliminate the need for "Private Sub Worksheet_Change". Do you think that'll work? Seems to be working right now. If there's something from the 2nd macro that I should be including in the 1st please let me know.

    Finally, would it be possible to add "Total Door Leafs" in the cell next to the sumproduct? If not, I'll manually type that in each time.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by EggsCell; 10-03-2018 at 01:20 PM.

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

    Re: Turn formula into macro

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, 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

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6)

  5. #5
    Registered User
    Join Date
    05-11-2016
    Location
    Dallas
    MS-Off Ver
    2016
    Posts
    8

    Re: Turn formula into macro

    Fixed! Thanks for letting me know. Didn't realize it wasn't showing up as code like it did on the initial post.

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

    Re: Turn formula into macro

    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 02-24-2017, 09:17 PM
  2. Manipulate Outlook Shortcuts (turn them on and turn them off) from excel vbascript
    By beckstei in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2016, 10:46 AM
  3. Turn off calculations before query refresh....turn them back on after
    By mk3ll00 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2014, 03:25 PM
  4. Auto calc on, then turn off, then runtime error how to turn back on
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-22-2011, 10:37 AM
  5. Turn an Excel Vlookup Formula into a Macro
    By Steve Strunk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2011, 12:27 PM
  6. Replies: 1
    Last Post: 07-30-2010, 03:35 PM
  7. pls turn this into VB macro
    By vickyho1008 in forum Excel General
    Replies: 11
    Last Post: 12-03-2006, 05:12 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