Creating complex search function

geperi

Board Regular
Joined
Apr 19, 2017
Messages
82
Office Version
  1. 365
Platform
  1. MacOS
Hi,

I have the following data in a sheet, and I am trying to create an easy to use search box in Excel that can give me the output I need.

The reason I need a search function is that I have more than 50 people doing tasks, and the excel has more than 50 columns. A nice search function would make things much easier.

Input: the tasks (there are no duplicates)
Output 1: Date
Output 2: Person

Is there a nice way to build a search function in Excel, where I can input the name of the task (maybe from a drop-down) and then I get the output 1 and 2 to appear automatically on separate cells?

Thank you!
Person 1Person 2 P3P4P5Etc..
Date 1Date 2date 3Date 4Date 5
Task 1Task AAAABCF
Task 2Task BBBBACG
Task 3Task CCCCAGH
Task 4DDAKL
Task 5EEA

<tbody>
</tbody>
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
The tasks you are looking up (Input), could you be looking up Task 1, Task 2, Task 3, Task 4, Task 5, Task A, Task B, Task C, etc.... just every task you listed? Or would you be looking up say Task 1, and then for the Person # you want it will output the first task for that person?
 
Upvote 0
This is event code. It assumes your data matrix begins in row 3, column A. It also assumes cell A1 as the input cell and cells B1:B2 as the output cells. To use the code once the data has been configured as above, right click the sheet name tab, then click 'View Code' in the pop up menu. Copy and paste the code into the large code pane of the vb editor. Close the editor and save the workbook as a macro enabled workbook to preserve the code. The code should now run when you make an entry into range A1 of the sheet and should return data from rows 3 and 4 of the data matrix for the column where a match is found for the value in cell A1.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo Hndl:
Dim fn As Range, rng As Range, lr As Long, lc As Long
If Not Intersect(Target, Range("A1")) Is Nothing Then
    With ActiveSheet
        lr = .Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
        lc = .Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious).Column
        Set rng = .Range("A3", .Cells(lr, lc))
        Set fn = rng.Find(Range("A1").Value, , xlValues, xlWhole)
            If Not fn Is Nothing Then
                .Range("B1") = .Cells(3, fn.Column).Value
                .Range("B2") = .Cells(4, fn.Column).Value
            End If
    End With
End If
Hndl:
Application.EnableEvents = True
If Err.Number <> 0 Then
    MsgBox Err.Number & ":  " & Err.Description
    On Error GoTo 0
End If
End Sub
 
Last edited:
Upvote 0
Here's one option:


Excel 2010
ABCDEFGH
1Person 1Person 2Person 3Person 4Person 5Task (Input)Task BB
2Date 1Date 2Date 3Date 4Date 5Date (Output)Date 3
3Task 1Task ATask AATask ABTask CFPerson (Output)Person 3
4Task 2Task BTask BBTask BATask CG
5Task 3Task CTask CCTask CATask GH
6Task 4Task DTask DATask KL
7Task 5Task ETask EA
Sheet1
Cell Formulas
RangeFormula
H2{=INDEX(A2:E2,SUMPRODUCT(MAX((A3:E7=H1)*(COLUMN(A3:E7))))-COLUMN(A3)+1)}
H3{=INDEX(A1:E1,SUMPRODUCT(MAX((A3:E7=H1)*(COLUMN(A3:E7))))-COLUMN(A3)+1)}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
This is event code. It assumes your data matrix begins in row 3, column A. It also assumes cell A1 as the input cell and cells B1:B2 as the output cells. To use the code once the data has been configured as above, right click the sheet name tab, then click 'View Code' in the pop up menu. Copy and paste the code into the large code pane of the vb editor. Close the editor and save the workbook as a macro enabled workbook to preserve the code. The code should now run when you make an entry into range A1 of the sheet and should return data from rows 3 and 4 of the data matrix for the column where a match is found for the value in cell A1.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo Hndl:
Dim fn As Range, rng As Range, lr As Long, lc As Long
If Not Intersect(Target, Range("A1")) Is Nothing Then
    With ActiveSheet
        lr = .Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
        lc = .Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious).Column
        Set rng = .Range("A3", .Cells(lr, lc))
        Set fn = rng.Find(Range("A1").Value, , xlValues, xlWhole)
            If Not fn Is Nothing Then
                .Range("B1") = .Cells(3, fn.Column).Value
                .Range("B2") = .Cells(4, fn.Column).Value
            End If
    End With
End If
Hndl:
Application.EnableEvents = True
If Err.Number <> 0 Then
    MsgBox Err.Number & ":  " & Err.Description
    On Error GoTo 0
End If
End Sub

Hi,

I used the exact code and set up the data in the page starting with A3, and tried to copy paste one task in A1 but nothing at all showed up in B1:B2..
 
Upvote 0
Hi all,

I thought about this a bit more, and I think it makes most sense if I go for a drop down functionality. Do you think this is do-able?

Input: Drop down 1: List of all dates
Input: Drop down 2: Based on the date chosen it will only show the Tasks associated with that specific date
Output: Text box: Person responsible
 
Upvote 0
Hi all,

I thought about this a bit more, and I think it makes most sense if I go for a drop down functionality. Do you think this is do-able?

Input: Drop down 1: List of all dates
Input: Drop down 2: Based on the date chosen it will only show the Tasks associated with that specific date
Output: Text box: Person responsible

Hi friends,

Is anyone able to help with a solution for my previous set-up above?

Would greatly appreciate it!
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,244
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top