Refix VBA to find and copy

septimus

Board Regular
Joined
Nov 20, 2014
Messages
69
I have some member of forum to write this code VBA in the past. It's done well. But after a period of time using, I got some trouble in my side. Could you please help me? I appreciate all your help!!!
I'd want to keep main structure of function "Finding"
As you can see in code. It only find/copy one string in one times finding in sheet "Filter_sheet" and only paste in A column in "Sheet1"
Now I want it be base on every the string that I paste in cell A1, B1, C1, D1, E1, F1, G1,H1 in "Sheet1" and find all of that string in sheet "Filter_sheet" then paste the found value to A2, B2,…,H2
For example:
I paste "M123" in cell A1, "M456" in cell B1 in sheet "Sheet1"
Code will find "M123" in sheet "Filter_sheet" and copy/paste all the value in column that have "M123" to column A from cell A2 in sheet "Sheet1"
Similar with "M456" will be found and copy/paste to column B from cell B2 in sheet "Sheet1"
Thank you for your help. I'll feedback all result. I'm so sorry if my english trouble you!

Private Sub CommandButton1_Click()
mySearch = InputBox("Enter search string") 'abcxyz
sht1 = "Filter_sheet"
sht2 = "Sheet1"
startColumn = 1000 'Column K
ii = 1
lastRow = Sheets(sht1).Range("A" & Rows.Count).End(xlUp).Row
i = 1
Do Until i > lastRow
If Not IsNumeric(Sheets(sht1).Cells(i, startColumn).Value) Then
lastColumn = Sheets(sht1).Cells(i, Columns.Count).End(xlToLeft).Column
c = startColumn
Do Until c > lastColumn
If Sheets(sht1).Cells(i, c).Value = mySearch Then
Sheets(sht2).Range("A" & ii).Value = Sheets(sht1).Cells(i, c).Value
ii = ii + 1
i2 = i + 1
Do Until IsNumeric(Sheets(sht1).Cells(i2, c).Value) = False Or _
IsEmpty(Sheets(sht1).Cells(i2, c).Value)
Sheets(sht2).Range("A" & ii).Value = Sheets(sht1).Cells(i2, c).Value
ii = ii + 1
i2 = i2 + 1
Loop
End If
c = c + 1
Loop
End If
i = i + 1
Loop
End Sub
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,203,242
Messages
6,054,345
Members
444,717
Latest member
melindanegron

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