+ Reply to Thread
Results 1 to 9 of 9

Have Userform read info from another sheet.

  1. #1
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Talking Have Userform read info from another sheet.

    Hi everyone,

    I have two sheets, the first is "Form" & the second is "Tracking". The "Form" sheet contains one button that, when clicked, brings up a userform. The userform has 11 checkboxes & two buttons ("View Next" & "View Previous"). The "Tracking" sheet has 11 columns (A - K), which will contain either "True" or "False".

    I need the checkboxes in the userform to pull the values from the "Tracking" sheet. For example, the "Tracking" sheet has the following information listed:

    A1 = True
    B1 = True
    C1 = True
    D1 = False
    E1 = True
    F1 = False
    G1 = False
    H1 = True
    I1 = False
    J1 = True
    K1 = True

    Therefore, the checkboxes in the userform should be displayed as :

    01 = Checked
    02 = Checked
    03 = Checked
    04 = Empty
    05 = Checked
    06 = Empty
    07 = Empty
    08 = Checked
    09 = Empty
    10 = Checked
    11 = Checked

    "True" = a ticked checkbox & "False" = an empty checkbox.

    What I also need, is that when the "View Next" button is clicked in the userform, the checkboxes change according to the new data. For example, when the userform is opened, it should default to the first row of data in the "Tracking" sheet, but when the "View Next" button is clicked, it should read from the second row of data, & so forth. The "View Previous" button should do the reverse, basically go from the second row to the first, or the fifth row to the fourth, & so on.

    I've attached an example of my worksheet to this post. Please note that this example is a minor section taken out of a much larger workbook that I'm working on, however I can't post everything due to having company (that I work for) information in the full copy; thus, I do apologize if the example worksheet is a bit rough.

    Any ideas

    Thanks,

    - I Love Lagar -
    Attached Files Attached Files
    Last edited by ilovelagar; 12-10-2009 at 03:52 PM. Reason: SOLVED

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Have Userform read info from another sheet.

    You can use the form.initialze event to assign controls initial values.
    Then by using a public variable you can keep track of the column you are currently on. See your example I have posted with code added for details.
    Attached Files Attached Files
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Have Userform read info from another sheet.

    Here's an alternative that uses a procedure within the userform to load the checkboxes, this saves repeating the code. Also, by using a consistent naming for the checkboxes, the original didn't, the code uses a loop to load them, reducing the lines of code. It also enables/disables the navigation buttons dependant on the row selected

    Please Login or Register  to view this content.
    See example in later post
    Last edited by royUK; 12-09-2009 at 03:12 PM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Exclamation Re: Have Userform read info from another sheet.

    Quote Originally Posted by davegugg View Post
    You can use the form.initialze event to assign controls initial values.
    Then by using a public variable you can keep track of the column you are currently on. See your example I have posted with code added for details.
    Your example works, however it's reading it horizontally (from column to column), for example:

    checkbox 01 = a1
    checkbox 02 = a2
    checkbox 03 = a3
    etc.

    I need it the other way around, vertically (from row to row):

    checkbox 01 = a1
    checkbox 02 = b1
    checkbox 03 = c1
    etc.

    I apologize if I miswrote what I needed in my original post.

    Thanks

  5. #5
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Have Userform read info from another sheet.

    Quote Originally Posted by royUK View Post
    Here's an alternative that uses a procedure within the userform to load the checkboxes, this saves repeating the code. Also, by using a consistent naming for the checkboxes, the original didn't, the code uses a loop to load them, reducing the lines of code. It also enables/disables the navigation buttons dependant on the row selected
    When I click the button in your example, I receive the following error:

    Run-Time Error '1004':
    Select method of Range class failed

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Have Userform read info from another sheet.

    Sorry about that, the way you had your second sheet set up made me think you were going by column. I didn't look closely enough. Here is a second example that goes by row. You can see the changes I made, basically just switching the coding to go by row instead of column.
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Have Userform read info from another sheet.

    I was getting strange results so i added a line to test it, then forgot to delete that line. Use this amended code
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by royUK; 12-09-2009 at 03:12 PM.

  8. #8
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Talking Re: Have Userform read info from another sheet.

    Thanks to both Davegugg & RoyUK, both your examples work perfectly! I'll just go on from here to see which code best fits my overall project, cheers

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Have Userform read info from another sheet.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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