Search range of cells from application input, for matchching cell values in cells specified from second application input.

BROWELL

New Member
Joined
Aug 11, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm going insane with this,

I'm trying to create a macro that allows me to firstly select a list of cell values (collumn/list) using application input (all different values.) we will call these my criteria.

I then need to search a list of data (collumn B) for any cells that match the criteria list, I then need the macro to copy the rows in which the matches have been made, copy them and then paste to worksheet "PREADVICE_SUMMARY"

I am quite new to this and may be being ambitious with trying to create something with such flexibility.

any assistance is appreciated

VBA Code:
Private Sub CommandButton21_Click()

Dim criteria As Range
Dim srchloc As Range

'specify list of cell values to search for match'
criteria = Application.InputBox(prompt = "Select cells as search criteria", Type:=8)
'specify list of cells to loop through.'
srchloc = Application.InputBox(prompt = "select cell range to search through", typ:=8)
'if either input is left blank exit.'
If criteria = "" Then Exit Sub
If srchloc = "" Then Exit Sub

Application.ScreenUpdating = False

Dim xRow&, NextRow&, LastRow&
NextRow = Sheets("PREADVICE_SUMMARY").Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
LastRow = Cells.Find(What:="*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For xRow = 1 To LastRow
If WorksheetFunction.CountIf(Rows(xRow), "*" & criteria & "*") > 0 Then
Rows(xRow).Copy Sheets("PREADVICE_SUMMARY").Rows(NextRow)
NextRow = Sheets("PREADVICE_SUMMARY").Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
End If
Next xRow
Application.ScreenUpdating = True
 
MsgBox "Macro is complete, " & NextRow - 2 & " rows containing" & vbCrLf & _
"''" & myWord & "''" & " were copied to Sheet2.", 64, "Done"

End Sub
 
Last edited by a moderator:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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