+ Reply to Thread
Results 1 to 4 of 4

trying to shorten code to get values from userform

  1. #1
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Cool trying to shorten code to get values from userform

    Below I have posted my code. The commented out section works just fine, but it is very lengthy.... The part that is not commented out is what I need to fix.

    here is my setup: I have a userform, each of the fields is custom named. I have those names listed across the top of a spreadsheet. My thought is to put those field names from the spreadsheet "QS" into an array "fieldval()" and then use the names in that array to return a value from the userform into a cell on the same spreadsheet.

    When I run the code it tells me that fieldval() is an invalid qualifier. How do I fix this?

    Please Login or Register  to view this content.
    Last edited by smokebreak; 01-29-2011 at 12:53 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: trying to shorten code to get values from userform

    Hello smokebreak,

    There is nothing in the posted code to suggest that fieldval is a qualifier. This would be easier to sort out if everything where available. Can you post the workbook?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Exclamation Re: trying to shorten code to get values from userform

    Leith,
    The sheet is attached.

    The code is on the userform module, on the btn_Submit_Click() event.

    It's kind of a lot of code, I hope you will not have an issue making sense of it.

    Thanks,
    Kevin
    Last edited by smokebreak; 01-29-2011 at 12:53 PM. Reason: edited attachment to remove sensitive info

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: trying to shorten code to get values from userform

    Hello smokebreak,

    Copying the values from so many controls is going to make your code long no matter want you do. You can speed the process by using an array. Once the array is loaded it can be assigned directly to a range, so no loop is needed.

    There were a couple of problems in the code, specifically with variable typing. The types for firstempty, lastcol, and fieldval() were incorrect. Those have been corrected. Here is the corrected code.
    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)

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