+ Reply to Thread
Results 1 to 7 of 7

VBA Excel - COUNT, AVG, & MIN with textboxes

  1. #1
    Registered User
    Join Date
    05-13-2013
    Location
    Savannan, TN
    MS-Off Ver
    Excel 2007
    Posts
    14

    VBA Excel - COUNT, AVG, & MIN with textboxes

    I have 25 text field boxes. Each one is labled as such: txt1, txt2, txt3, txt4, etc. What I need to do is have it loop though and find the AVG and MIN of all text boxes while also excluding any zeros and being able to count how many non zeros are entered.
    For example...

    txt1 - 456
    txt2 - 455
    txt3 - 456
    txt4 - 0
    txt5 - 449
    txt6 - 445

    The average would be 452.2 and the minimal number would be 445. Altough 6 boxes have been filled in, only 5 boxes have non "0" in them so therefore the COUNT fould be 5. Only these three numbers would theen be submitted to my excel sheet.

    I know how to do all this via excel but it would be so much easier (in my own thinking) to just allow this form do all the work. There will be 3 different people using this form a day and 2 of them hate and dispise of excel, so that was the reason behind all of this.

    Everything is already set up and ready to submit, I just can't figure the looping process out.

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: VBA Excel - COUNT, AVG, & MIN with textboxes

    try this:
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-13-2013
    Location
    Savannan, TN
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VBA Excel - COUNT, AVG, & MIN with textboxes

    Thanks so much for your help on getting this resolved for me.

    It works great, except, I need the three numbers - count, avg, & min - to be submitted to a spreadsheet not a msgbox. Should I create another control button and call it "calculate" and then have the data sent to another text field which then have the submitt button? Which would be the easiest to do?

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

    Re: VBA Excel - COUNT, AVG, & MIN with textboxes

    Hi

    TehneXus has given you three variables avg, min, max.

    if you want these on a spread sheet then delete the section of code that opens the msgbox and write the variables to the spreadsheet

    Sheets("Output").select
    range("A1").value = avg
    range("A2").value = min
    range("A3").value = max

  5. #5
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: VBA Excel - COUNT, AVG, & MIN with textboxes

    hi,

    replace the msgbox with
    Please Login or Register  to view this content.
    it will write the values into sheet1, row2, A:C.

    Regards

  6. #6
    Registered User
    Join Date
    05-13-2013
    Location
    Savannan, TN
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VBA Excel - COUNT, AVG, & MIN with textboxes

    Why would I be getting an error with my code?

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: VBA Excel - COUNT, AVG, & MIN with textboxes

    you haven't set anything to 'ws'
    try
    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)

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