+ Reply to Thread
Results 1 to 13 of 13

Using a lookup function as a part of a form

  1. #1
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Using a lookup function as a part of a form

    Hello,

    What I am trying to do is create a part of a macro that will look up an entry in a form, find that related cell and then enter in the rest of the form from there. The reason that I say part is that I have the form formatted already (mostly).

    So for instance the form would read as:
    Room Number: 12
    Name: Bob
    Address: The Universe

    So 12 would be looked up in colum A and then Bob and The universe would be entered in the corresponding row in columns B and C.

    Hopefully this makes sense and thanks in advance!
    Last edited by NBVC; 08-26-2011 at 08:49 AM. Reason: Marked Solved per OP request via PM

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Using a lookup function as a part of a form

    KaitMacN,

    Any chance you could post a copy of the workbook (with all sensitive data deleted or changed) in xls format. It would be easier to give you customized advice without having to guess/recreate the userforms.

    In general terms, you'd likely need to use the TextBox_Exit event as a trigger to look up the room number in column A. The value in the Textbox can be treated as a variable, and the .Find method can be used to find it in column A. Then, the .Offset method can be used to pull information in subsequent columns from the same row.

  3. #3
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Using a lookup function as a part of a form

    Yes of couse!
    I am just starting using VBA so if anyone has a suggestion for a good place to have programming talk "translated" into english that would be great as well.

    Thanks
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Using a lookup function as a part of a form

    KaitMacN,

    I'm attaching a new copy of your workbook. I included a new userform (UserForm2) which demonstrates how I would work this. I included a new ComboBox that includes all of the room numbers to be selected. Once selected, the corresponding txtboxes are populated. Please note, I included random numbers in some of your cells. I did this simply as a test to make sure it's working correctly. You can delete them.

    See attached and report back with any questions.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Using a lookup function as a part of a form

    For some reason when I try getting a "run-time error '424' any ideas as to why this may be happening?
    Thanks for all your help

  6. #6
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Using a lookup function as a part of a form

    Hi Kait,

    Are you getting an error when you launch my userform, UserForm2? Or are you getting an error on your amended code? If the latter, can you please post the code that you are using?

  7. #7
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Using a lookup function as a part of a form

    Now I am not getting the error i did well im not sure what but when i click the "ENTER" button nothing is happening.
    PS i love the drop down for the rooms

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Using a lookup function as a part of a form

    Please Login or Register  to view this content.
    That is the only other code that is written

  9. #9
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Using a lookup function as a part of a form

    There's no code attached to the Enter button in userform2. As it stands, the code we have populates the comboboxes with data that already exists in the Worksheet based on the room selection. Is this what you needed to do initially?

    Next, do you want to be able to modify the individual textboxes, then pass that information along to the Worksheet once the enter button is pressed? If so, let me know and we can work on some code for that.

  10. #10
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Using a lookup function as a part of a form

    In the end the document will be used to track room occupancy for long term stays. As such what I would LOVE when all is said in done is that:

    select the room on the form, fill in the information on there and then press enter.
    After pressing enter the computer will brilliantly locate the room and fill in the rest of the information!

    I would also want to have another macro that lookups the room number and clears the cells for when people have moved out but I will be happy with the first part!

    Did that make more sense? If I am saying the same thing that you are I appologize I was getting lost with comboboxes etc :P

  11. #11
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Using a lookup function as a part of a form

    I see what you need to do. I think I actually worked backwards, presuming the information was already in the form and you needed to populate it into the userform. As such, and I apologize, our previous code was a bit of a waste of time. (Hopefully, it was informative if nothing else).

    I cleaned up the code a bit. Now you can add all of the relevant information and it gets populated into the worksheet. I used a loop this time for efficiency, so let me know if that is confusing. I also included a "Check Out" button which will clear entries for someone who has checked out. Let me know how its working out for you.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-03-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Using a lookup function as a part of a form

    YAY!!
    As that was working so well I decided to make it more complicated :P
    I have included the attachment where I was trying to add checkboxes (sheet C46), i think i started the code in the right place however and being told that the sub or function is not defined.
    I really appreciate all the assistance with this I am MAYBE starting to get bits and pieces.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Using a lookup function as a part of a form

    Change your command button click even to the following:
    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