Help with vba using VlookUp
Results 1 to 10 of 10

Thread: Help with vba using VlookUp

  1. #1
    Board Regular
    Join Date
    Jan 2016
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Help with vba using VlookUp

    Hi Everyone,

    My Question today is about using vlookup in vba, or something of the like.
    I have 2 worksheets one named "Members" the other named "Fees Paid". Currently i am using vlookup in cells that require it, what i would like to do is use vba to accomplish this task instead.

    The "Members Sheet " is where all data is manually entered, The "Fees Paid Sheet" has 8 Columns "A" through to "H" column A uses vlookup, column B uses Data Validation List, Column's C,D & E all use vlookup, Once the user selects a name in column B then the rest of the columns return the matching Data for that name.

    is there a way to have vba do this so that i can remove all formulas from column's A,C,D & E....? This must continue down the worksheet over time until the worksheet is full.

    Thankyou all in advance...

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,673
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Help with vba using VlookUp

    Try this

    Put the following code in the event of the sheet "Fees paid"


    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Count > 1 Then Exit Sub
      If Target.Value = "" Then Exit Sub
      Dim sh As Worksheet, f As Range
      If Not Intersect(Target, Range("B:B")) Is Nothing Then
        Set sh = Sheets("Members")
        Set f = sh.Range("A:A").Find(Target.Value, , xlValues, xlWhole)
        If Not f Is Nothing Then
          'cell destination              cell origin
          Cells(Target.Row, "A").Value = sh.Cells(f.Row, "B").Value
          Cells(Target.Row, "C").Value = sh.Cells(f.Row, "C").Value
          Cells(Target.Row, "D").Value = sh.Cells(f.Row, "D").Value
          Cells(Target.Row, "E").Value = sh.Cells(f.Row, "E").Value
          Cells(Target.Row, "F").Value = sh.Cells(f.Row, "F").Value
          Cells(Target.Row, "G").Value = sh.Cells(f.Row, "G").Value
          Cells(Target.Row, "H").Value = sh.Cells(f.Row, "H").Value
        Else
          MsgBox "Member does not exists"
        End If
      End If
    End Sub
    You did not mention in which column of the "members" sheet the search is performed, then change "A:A" to that column.


    You must also adjust the destination columns and the origin column.


    SHEET EVENT
    Right click the tab of the sheet you want this to work (Fees paid), select view code and paste the code into the window that opens up.

    Then, when you select a member on the "Fees paid" sheet, the macro automatically runs.


    Let me know if you have any doubt.
    Regards Dante Amor

  3. #3
    Board Regular
    Join Date
    Jan 2016
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help with vba using VlookUp

    Hi DanteAmor,

    Appologise it searchs the Members sheet columns "B, C, D, E, F & G"

  4. #4
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,734
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Help with vba using VlookUp

    Are you saying when you enter "Alpha" in column A of Fees Paid sheet you want the script to look in sheet named Members Column A for "Alpha" and then copy the whole row from sheet Members to sheet Fees Paid?
    Last edited by My Aswer Is This; Aug 19th, 2019 at 07:01 PM.
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please I’m not perfect yet. "Memories are forever"

  5. #5
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,673
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Help with vba using VlookUp

    Quote Originally Posted by Gregm66 View Post
    Hi DanteAmor,

    Appologise it searchs the Members sheet columns "B, C, D, E, F & G"
    I am not understanding, you could give some examples.
    Or the formulas you are using.
    Regards Dante Amor

  6. #6
    Board Regular
    Join Date
    Jan 2016
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help with vba using VlookUp

    The columns in the Members sheet hold the members names ph numbers etc, if in column B on the fees paid sheet the user selects a members name, then columns A,C,D & E need to seach the members sheet and return the matching details for that particular member...
    the vlookup in each cell that i am using to do this looks like see below..

    Code:
    =IFERROR(VLOOKUP(B2,Members,2,FALSE),"")

  7. #7
    Board Regular
    Join Date
    Jan 2016
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help with vba using VlookUp

    Sorry the above code is in the fees paid sheet..
    the code is in column "A" column "C" column "D" column "E"

  8. #8
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,673
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Help with vba using VlookUp

    Did you try the macro?
    Regards Dante Amor

  9. #9
    Board Regular
    Join Date
    Jan 2016
    Posts
    129
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help with vba using VlookUp

    Thankyou DanteAmor

    the code that you supplied works i just need to change it around alittle but it works fine...

    Thankyou everyone for your help, my problem with this one has been solved...

  10. #10
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,673
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Help with vba using VlookUp

    Quote Originally Posted by Gregm66 View Post
    Thankyou DanteAmor

    the code that you supplied works i just need to change it around alittle but it works fine...

    Thankyou everyone for your help, my problem with this one has been solved...

    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

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
  •