+ Reply to Thread
Results 1 to 5 of 5

Code to Get Value from Form and Add to Total

Hybrid View

TFiske Code to Get Value from Form... 01-23-2018, 02:34 PM
ranman256 Re: Code to Get Value from... 01-23-2018, 02:49 PM
TFiske Re: Code to Get Value from... 01-24-2018, 10:07 AM
TFiske Re: Code to Get Value from... 01-24-2018, 03:52 PM
TFiske Re: Code to Get Value from... 01-24-2018, 09:58 AM
  1. #1
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Code to Get Value from Form and Add to Total

    Hi all,

    Very new to VBA.

    We order large amounts of annual flowers for a city beautification program every year. The orders come in from citizens and groups that have adopted a flower planter around the city. I am trying to devise a faster way of totaling up the flower orders and keeping track of what each group ordered.

    In the attached sample, the user would enter how many flats of each variety of flower by color in the table in "Flower Order Entry."

    The Enter button on the "Flower Order Entry" would run a macro that:

    1) grabs the values entered into the table and the group name from "Flower Order Entry" and basically copy/paste to the first available row in the "Total Flower Order" tab (Columns A:V).
    2) adds up all the orders by flower type and color in AA4:AS26 of the "Total Flower Order" tab. The Sample sheet has expected values.

    This is just an idea of how to do this. If anyone has another suggestion of how to build this, I'd love to hear it. Thanks!!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,192

    Re: Code to Get Value from Form and Add to Total

    If you enter data (shown in image), this is better for excel to summarize.
    Once all the data is in this format, a pivot table will produce the list for everyone. (like your other sheets)
    Attached Images Attached Images

  3. #3
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Code to Get Value from Form and Add to Total

    I'm trying to automate the data entry process. In my first model, my goal is to reduce the amount of data entry to only the number of flats ordered. Going with your suggestion, is there a way to use my original form to automatically populate a table that could then be summarized with a pivot table?

  4. #4
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Code to Get Value from Form and Add to Total

    I did some research and came up with the following code:

    Sub FlowerOrderWizard()
    
    ' Keyboard Shortcut: Ctrl+t
    '
    ' Declares the ranges that will be copied and/or cleared.
    Dim SrtRange As Range
    Dim OrderRange As Range
    Dim ClrOrderRange As Range
    
    Set SrtRange = Sheets("Flower Order Entry").Range("B2")
    Set OrderRange = Sheets("Flower Order Entry").Range("B4:W27")
    Set ClrOrderRange = Sheets("Flower Order Entry").Range("E4:W26")
    
    ' Selects and copies the flower order range from "Flower Order Entry" B4:W27,
    ' including the "END" tag at B27 used by the loop to find the end of the table
        Sheets("Flower Order Entry").Activate
        OrderRange.Select
        Selection.Copy
        
        Sheets("Total Flower Order").Activate
        
        Dim loopBool As Boolean
        loopBool = True
        Sheets("Total Flower Order").Range("A1").Activate
        Do While loopBool = True
            If ActiveCell.Value = "END" Then
                loopBool = False
            Else
                ActiveCell.Offset(1, 0).Activate
            End If
        Loop
        
    ' Pastes the data copied from "Flower Order Entry" to end of the table
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
    ' Returns the user to the "Flower Order Entry" tab and clears the ranges for
    ' Group Name and the quantity of flats
        Sheets("Flower Order Entry").Activate
        ClrOrderRange.ClearContents
        SrtRange.ClearContents
        SrtRange.Select
                
    End Sub
    Then the SUMPRODUCT function uses some dynamic named ranges to total all entries by flower type and color in "Total Flower Order"AA2:AS24

    =IF(SUMPRODUCT((RefRng_CommonNames=$Z2)*(Rng_FlowerColor=AA$1)*Ary_AllFlowerOrders)=0,"",SUMPRODUCT((RefRng_CommonNames=$Z2)*(Rng_FlowerColor=AA$1)*Ary_AllFlowerOrders))
    If anyone has any feedback on this approach, I'd really appreciate it. Please see the attached sample.
    Attached Files Attached Files
    Last edited by TFiske; 01-24-2018 at 05:09 PM. Reason: Updated Code with Comments

  5. #5
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Code to Get Value from Form and Add to Total

    So you're suggestion is to manually enter the orders into a single table and then summarize with a pivot table?

+ 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. code to create unique alphanumeric form number every time form is opened
    By Ishwarind in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-01-2014, 06:16 AM
  2. [SOLVED] Help me streamline my code? Determine form button background from form text box
    By tivofan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2013, 10:09 AM
  3. To show total records in use form ( Record 7 of 10)
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2010, 06:21 AM
  4. Order Form Sub-Totals and Total Amounts Help
    By jstnvndn in forum Excel General
    Replies: 1
    Last Post: 08-29-2007, 06:04 PM
  5. best way to total items on order form
    By mkmed in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-16-2007, 02:00 PM
  6. Keep a running total while using a clearable form
    By 1vagrowr in forum Excel General
    Replies: 3
    Last Post: 12-20-2005, 03:15 PM
  7. how can I have Excel total a column of # that were derived by form
    By Samantha in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-10-2005, 02:20 AM

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