Help with vba using VlookUp

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
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...
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,207
Office Version
2007
Platform
Windows
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("[COLOR=#ff0000]A:A[/COLOR]").Find(Target.Value, , xlValues, xlWhole)
    If Not f Is Nothing Then
      '[COLOR=#0000ff]cell destination              cell origin[/COLOR]
      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.
 

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
Hi DanteAmor,

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

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,762
Office Version
2013
Platform
Windows
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:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,207
Office Version
2007
Platform
Windows
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.
 

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
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),"")
 

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
Sorry the above code is in the fees paid sheet..
the code is in column "A" column "C" column "D" column "E"
 

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
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...
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,207
Office Version
2007
Platform
Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,630
Messages
5,488,004
Members
407,617
Latest member
Samanthad2007

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top