Match all values in one column based on combobox selection and find a value in second column based on combobox value.

Mike Neal

New Member
Joined
May 24, 2020
Messages
38
Office Version
  1. 2013
Platform
  1. Windows
I have a combobox that contains Equip IDs and one that contains Task IDs. I would like to search column A for the Equip ID which there may be several instances of and with a second combobox select a Task ID in Column B that is in the same row as the Equip ID. After finding the matched pair I would like to use a command button to put today's date in the next empty cell in that row. This will be an ongoing record so I need to look for the next empty column each time the task is completed. This macro also needs to find the same matched pair in a different sheet with Column A being the Equip ID again and Column B being the Task ID and delete the entire row from the second sheet. I have been looking at making arrays to do this but nothing I've tried comes close to working. Any help would be appreciated. Thank you.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The method below works but probably need to amend these 3 lines
Set ws = Sheets("Sheet1")
cb1 = ComboBox1.Text
cb2 = ComboBox2.Text
If you need help, then I need to know where the comboboxes are located (worksheet or userform) and, if on worksheet, whether they are Form Controls or Active-X objects

VBA Code:
    Dim ws As Worksheet, matchFormula As String, cb1 As String, cb2 As String
    Set ws = Sheets("Sheet1")
    cb1 = ComboBox1.Text
    cb2 = ComboBox2.Text
    matchFormula = "match(" & Chr(34) & cb1 & cb2 & Chr(34) & ",A:A&B:B,0)"

    On Error Resume Next
    ws.Cells(Evaluate(matchFormula), ws.Columns.Count).End(xlToLeft).Offset(, 1) = Date
    On Error GoTo 0

After getting it to work, adapt to also delete the same pair from the 2nd sheet
 
Upvote 0
The method below works but probably need to amend these 3 lines
Set ws = Sheets("Sheet1")
cb1 = ComboBox1.Text
cb2 = ComboBox2.Text
If you need help, then I need to know where the comboboxes are located (worksheet or userform) and, if on worksheet, whether they are Form Controls or Active-X objects

VBA Code:
    Dim ws As Worksheet, matchFormula As String, cb1 As String, cb2 As String
    Set ws = Sheets("Sheet1")
    cb1 = ComboBox1.Text
    cb2 = ComboBox2.Text
    matchFormula = "match(" & Chr(34) & cb1 & cb2 & Chr(34) & ",A:A&B:B,0)"

    On Error Resume Next
    ws.Cells(Evaluate(matchFormula), ws.Columns.Count).End(xlToLeft).Offset(, 1) = Date
    On Error GoTo 0

After getting it to work, adapt to also delete the same pair from the 2nd sheet
That worked great for finding the match and adding the date. I am not sure how to adapt it to delete and entire row on the other sheet though. I am using VBA userform comboboxes. My second sheet is "Sheet1" the data is in the same locations: column A = "Equip ID" and column B = "Task ID" as the first sheet. The comboboxs are named "TASKS_EQUIP_ID_LIST" and "TASKS_TASK_DUE_LIST". Thanks again for the help.
 
Upvote 0
That worked great for finding the match and adding the date. I am not sure how to adapt it to delete and entire row on the other sheet though. I am using VBA userform comboboxes. My second sheet is "Sheet1" the data is in the same locations: column A = "Equip ID" and column B = "Task ID" as the first sheet. The comboboxs are named "TASKS_EQUIP_ID_LIST" and "TASKS_TASK_DUE_LIST". Thanks again for the help.
Dim ws As Worksheet, matchFormula As String, cb1 As String, cb2 As String
Set ws = Sheets("Task Due Dates")
cb1 = TASKS_EQUIP_ID_LIST.Text
cb2 = TASKS_TASK_DUE_LIST.Text
matchFormula = "match(" & Chr(34) & cb1 & cb2 & Chr(34) & ",A:A&B:B,0)"
Worksheets("Task Due Dates").Cells(Evaluate(matchFormula), ws.Columns.Count).End(xlToLeft).Offset(, 1) = Date
On Error GoTo 0

This is what I am using altered from what was posted with the actual comboboxes and reference to the sheet. I added the sheet to the evaluation line to help with a problem I noticed after running the code a few times. If I have the "Task Due Dates" sheet visible everything goes in the right place but if I have a different sheet in the same workbook open the dates don't end up in the right row. Not sure why this is happening. I noticed that when I choose R400/T204 the date goes below the task ID 3 rows down and when I chose R500/T107 the date went beside R500/T106. It is important that the dates end up in the right place without actually viewing the sheet. Do I need to declare the sheet as active?

Equip IDTask ID
R400T2046/29/2020
R500T1076/29/2020
R500T1066/29/2020
R500T105
6/29/2020
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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