I searched the other pages that seemed to be answering the question. I have tried to do this using the if-then formula between sheets, but it doesn't work well with multiple cells / columns. I can't figure it out.
I saw somewhere that a person suggested a query (but that was for use in Google and doesn't work in Excel). Any suggestions on how to best do this?
I am trying to create a consultant database in Excel. We use consultants on projects, and various consultants perform X number of jobs.
Sheet 1 would be the master list with the following data
A1 - Company Name
B1 - Specialty 1
C1 - Specialty 2
D1 - Specialty 3
(and so forth - probably up to 10 specialties), Then
L1 - Key Contacts
M1 - Email 1
N1 - Email 2
O1 - Email 3
P1 - Email 4
Q1 - Previous Projects
and so on (there may be cell phone numbers and more added)
Sheet 2 and beyond would populate based on specialty.
Let's say Sheet 2 is called Architects. If one of the specialties matches "Architect", I'd want it to provide me the following on the Architects sheet (sheet 2):
A1 Company Name
B1 Key Contacts
C1 Email1
D1 Email2
E1 Email3
F1 Email4
G1 Previous Projects
Can someone please help me figure out how to auto populate? As the master sheet changes, it will be imperative I don't have to constantly update the other sheets.
Potential "Query" sheet Worksheet_Change
event (ie this code should be pasted into the code module of the actual sheet you use for the "querying"):
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
On Error GoTo ReEnableEvents
Application.EnableEvents = False
Dim lastRow As Long
Dim r As Long
Dim c As Long
Dim newRow As Long
Dim Speciality As String
Speciality = Range("A1").Value
'clear existing data
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
If lastRow > 2 Then ' Assume headings are on row 2
Rows("3:" & lastRow).ClearContents
End If
'find new data
newRow = 2
With Worksheets("MasterList")
For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
For c = 2 To 11 ' loop through the speciality columns
If .Cells(r, c).Value = Speciality Then
newRow = newRow + 1
Cells(newRow, "A").Value = .Cells(r, "A").Value
Cells(newRow, "B").Value = .Cells(r, "L").Value
Cells(newRow, "C").Value = .Cells(r, "M").Value
Cells(newRow, "D").Value = .Cells(r, "N").Value
Cells(newRow, "E").Value = .Cells(r, "O").Value
Cells(newRow, "F").Value = .Cells(r, "P").Value
Cells(newRow, "G").Value = .Cells(r, "Q").Value
Exit For
End If
Next
Next
End With
ReEnableEvents:
Application.EnableEvents = True
End Sub
This assumes that cell A1 of the "Query" sheet is the value you want to look for (ie the "Speciality"), that row 2 of that sheet will have headings, and that rows 3 onward will be populated with the results.
I haven't tested it, but it should be close to what you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.