+ Reply to Thread
Results 1 to 5 of 5

userform button click stores a variable (number of clicks)

  1. #1
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    userform button click stores a variable (number of clicks)

    I'm not sure if this is possible, or if there is a better way to do it...

    What I would like to do is in my userform, use my command button that runs all of my code to store a variable that is the number of times it has been clicked.

    With this number, I would like to use that to keep track of what the click number was and for that number what the selections in my listbox were.

    The selections in my listbox are put into cells on the sheet the macro is on, and these cells are copied to the worksheet called Hist, and this is where I want the copied selections to be matched with a specific mouse click. So each mouse click is associated with one set of copied data. I hope that makes sense. I can post my code, but I just want to get an idea if this is possible or not.

    Thank you!

  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: userform button click stores a variable (number of clicks)

    Hello JayEmTee91,

    There a few ways to store the number of times the button is clicked. The easiest would to be use a cell on one the worksheets. To prevent the users from changing the value, you could hide the column.

    Another way would be to use a worksheet just for this purpose and hide it as xlVeryHidden. The user will not be able to unhide the sheet but you will be able to access it from code.

    If the program will remain on only computer, you could save the count to the registry using VBA methods GetSetting and SaveSetting. No special access rights are required to save or return a value from the registry with this code.

    Lastly, you could save everything in a text file. The count number and the ListBox selections would all be together in one place. You could import this information from the file to worksheet and even create individual files for users, days of the month, etc.
    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
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Re: userform button click stores a variable (number of clicks)

    I would like to take the route of storing the value in a cell. How would I go about doing so?

  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: userform button click stores a variable (number of clicks)

    Hello JayEmTee91,

    Here is an example that you will need to adapt to your situation. This simply tracks the number of times the button has been clicked. The code assumes that CommandButton1 is the name of button the user is clicking.

    UserForm Command Button Code
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Re: userform button click stores a variable (number of clicks)

    I could not get the way you suggested to work given my code, but the following code allows me to do what I want.

    With each click in the userform, the counter and all the information in the click is moved to another sheet called history, and since the information that is copied occupies 2 rows, i want it to skip a row and then continue onto the one after that. Each click stores history based on the number.

    The code that I have messes up on the first two clicks. The first click puts the items that were copied in the first spot I want, but then the second click overwrites the first clicks copy. The third click skips a line and copies the information correctly. I do not understand why that is. My code is below:

    This code is for the counter...
    Please Login or Register  to view this content.
    This code is for the copy command.
    Please Login or Register  to view this content.
    Any suggestions would be appreciated!

+ 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