User Form searching from two different columns

JarmoVee

New Member
Joined
May 27, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have an user form for searching data from worksheet "Data".
Now I can search only data from column A (1). Is this possible to get do searching also column B (2)?

Thank you in advance!

VBA Code:
Private Sub cmdSearch_Click()

Dim RowNum As Long
Dim SearchRow As Long

RowNum = 2
SearchRow = 2

Worksheets("Data").Activate

Do Until Cells(RowNum, 1).Value = ""

    If InStr(1, Cells(RowNum, 1).Value, txtKeywords.Value, vbTextCompare) > 0 Then
  
    
        Worksheets("Product Search").Cells(SearchRow, 1).Value = Cells(RowNum, 1).Value
        Worksheets("Product Search").Cells(SearchRow, 2).Value = Cells(RowNum, 2).Value
        Worksheets("Product Search").Cells(SearchRow, 3).Value = Cells(RowNum, 3).Value
        Worksheets("Product Search").Cells(SearchRow, 4).Value = Cells(RowNum, 4).Value
        Worksheets("Product Search").Cells(SearchRow, 5).Value = Cells(RowNum, 5).Value
        Worksheets("Product Search").Cells(SearchRow, 6).Value = Cells(RowNum, 6).Value
        Worksheets("Product Search").Cells(SearchRow, 7).Value = Cells(RowNum, 7).Value
        Worksheets("Product Search").Cells(SearchRow, 8).Value = Cells(RowNum, 8).Value
        Worksheets("Product Search").Cells(SearchRow, 9).Value = Cells(RowNum, 9).Value
        Worksheets("Product Search").Cells(SearchRow, 10).Value = Cells(RowNum, 10).Value
        Worksheets("Product Search").Cells(SearchRow, 11).Value = Cells(RowNum, 11).Value
        Worksheets("Product Search").Cells(SearchRow, 12).Value = Cells(RowNum, 12).Value
        Worksheets("Product Search").Cells(SearchRow, 13).Value = Cells(RowNum, 13).Value
        Worksheets("Product Search").Cells(SearchRow, 14).Value = Cells(RowNum, 14).Value
        Worksheets("Product Search").Cells(SearchRow, 15).Value = Cells(RowNum, 15).Value
        Worksheets("Product Search").Cells(SearchRow, 16).Value = Cells(RowNum, 16).Value
        SearchRow = SearchRow + 1
    End If
    RowNum = RowNum + 1
Loop

If SearchRow = 2 Then
    MsgBox "xxx"
    Exit Sub
End If

lstSearchResults.RowSource = "SearchResults"

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
How about
VBA Code:
Private Sub cmdSearch_Click()

Dim RowNum As Long
Dim SearchRow As Long

RowNum = 2
SearchRow = 2

Worksheets("Data").Activate

Do Until Cells(RowNum, 1).Value = ""

    If InStr(1, Cells(RowNum, 1).Value, txtKeywords.Value, vbTextCompare) > 0 _
      Or InStr(1, Cells(RowNum, 2).Value, txtKeywords.Value, vbTextCompare) > 0 Then
  
    
        Worksheets("Product Search").Cells(SearchRow, 1).Resize(, 16).Value = Cells(RowNum, 1).Resize(, 16).Value
        SearchRow = SearchRow + 1
    End If
    RowNum = RowNum + 1
Loop

If SearchRow = 2 Then
    MsgBox "xxx"
    Exit Sub
End If

lstSearchResults.RowSource = "SearchResults"

End Sub
 
Upvote 0
Solution
Thanks again! This is an incredibly great place for a beginner to get help quickly. I work in a small company and have taken it as my own project to get easier work with Excel. So I will continue to ask for some help, but the project will be ready soon.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
May I ask one more thing...? :)

How can I do "Update" for the product what found with searching?
When I click searched product, it shows me all the data in text boxes (see photo). Now if I need to do update, I don't understand how to do it.


1623083228244.png
 
Upvote 0
As this is a totally different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,971
Members
449,276
Latest member
surendra75

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