Lookup Name in Multiple Fields

Rcaaa

New Member
Joined
May 21, 2018
Messages
22
Hello,

I am working on a spreadsheet that has the following setup. What would be the best way to find out which projects each person is on? I was thinking of doing a vlookup, but I would like to know if there is a better alternative.

Project
Resource 1
Resource 2
Resource 3
Resource 4
1
Ana
Rob
Jim
Erica
2
Rob
Susan
Tim
Kyle

<tbody>
</tbody>

Thanks,

RCA
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,076
Office Version
2019
Platform
Windows
With a worksheet that looks like this

vABCDE
1ProjectResource 1Resource 2Resource 3Resource 4
21AnaRobJimErica
32RobSusanTimKyle
43AnaRobJimErica
54RobSusanTimKyle
65AnaRobJimErica
76RobSusanTimKyle

The following code will tell you on Sheet 2 which projects a person is working on when you enter this code and follow the prompts

Code:
Option Explicit


Sub projectX()
    Dim lr As Long, lc As Long, c As Range
    Dim rng As Range, lr2 As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    Set rng = Range(Cells(2, 1), Cells(lr, lc))
    Dim crit As String, trow As Long
    crit = InputBox("Which person to search?")
    For Each c In rng
        If c = crit Then
            trow = c.Row
            lr2 = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
            Range("A" & trow).Copy Sheets("Sheet2").Range("A" & lr2 + 1)    'make sure you have set up a sheet2
        End If
    Next c
End Sub
 

Rcaaa

New Member
Joined
May 21, 2018
Messages
22
Thanks for sharing. Would you be able to recommend a resource to learn how to create VBA coding similar to this. I would like to learn how to do it for myself.

Thanks,

RCAAA
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,076
Office Version
2019
Platform
Windows
Check out Mr Excel's books. I used one from 2010 but I am sure he has updated them. Go to the home page for this site.
 

Forum statistics

Threads
1,082,318
Messages
5,364,518
Members
400,804
Latest member
davileal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top