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
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: