Results 1 to 3 of 3

Thread: Excel Userform question (passing values and lookup)
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2005
    Posts
    154
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Excel Userform question (passing values and lookup)

    Hi,

    I'm looking for some guidance.. I've got the following setup:

    (1) A userform which acts as a search interface
    (2) A useform which 'should' show the individual record details selected in (1)

    The source data is in a table and I can successfully pass the correct table row number to the second userform.. **BUT** I'm not sure how to use this value to lookup the data for the rest of the fields in the corresponding row to populate the userform?!

    The VBA for the second userform is shown below:


    Private Sub UserForm_Activate()

    With Me
    .txtRow.Value = Me.Tag
    .txtArea.Value = Application.VLookup(Me.Tag, Sheets("SHEET1").Range("A6:AS4336"), 3, False)

    End With
    End Sub


    I doesn't seem to like the 'Me.Tag' expression... can anyone offer any ideas or suggestions?? - I've been searching for a bit and can't really find a suitable answer.. thanks for any help or advice offered!

  2. #2
    Board Regular steve the fish's Avatar
    Join Date
    Oct 2009
    Location
    Midlands, UK
    Posts
    7,649
    Post Thanks / Like
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Excel Userform question (passing values and lookup)

    I dont know what doesnt seem to like means but Me.Tag should produce the tag of the initialised userform.
    Looking for opportunities

  3. #3
    Board Regular
    Join Date
    Jun 2005
    Posts
    154
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel Userform question (passing values and lookup)

    EDIT: I was being stupid... (not surprising if you knew me) - I hadn't had my morning coffee...

    there was a type mismatch!! - and figured it was easier to pass the Tag value to another object - so working code now looks like this :


    Private Sub UserForm_Activate()

    With Me
    .txtRow.Value = Me.Tag
    .TextBox1.Value = .txtRow.Value 'stores the Row number for the below lookups
    .txtArea.Value = Application.VLookup(CLng(TextBox1.Value), Sheets("SHEET1").Range("A6:AS4336"), 3, False)
    End With
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •