Excel - search partially

RJ1969

Board Regular
Joined
Sep 13, 2014
Messages
76
Hi guys,
I have this worksheet that I am working on. It has a userform. When I click thebutton from the worksheet then the userform will pop up. The textbox1 has thisdropdown box where I select the company names. The list of companies has about300 listed.I have to use the down arrow to search each individual from thetextbox1.

Is there anyway that you can edit this code (see below) for me to be able tosearch or looks for words that partially match that is on the list?
Example: General Albertson Gas Company, Gutierrez Gas Tile Company, Marian SaltLite Corp. .... When I search and type Gas then all the one that has word"gas" will be partially be showing so I can select.

Here is the code I have so far.
Code:
Const header = "C12,a ,k22,a ,o22,a ,n23,a,v23,a ,n24,a ,v24,a ,n25,a ,x25,a ,e30,a,e31,a ,d44,a"
Const Secflr = " Address Incomplete.|Appearance date on the citation is not readable.|" & _
    " Appearance date on the citation is not valid.| Appearance Date on the citation is/was scheduled on the Holiday.|" & _
      "the citation.|You requested that we return thecitation to you.|" & _
      ""
Const mySheet = "Sheet1"
Private Sub CmdClearEntry_Click()
    Dim ct                    As Control
    tmpfmen = ""
    tmpcben = ""
    For Each ct In Me.Controls
        If InStr(ct.Name, "TextBox") > 0 Then
            tmpfmen = tmpfmen & ct & "|"
            ct = ""
        ElseIf InStr(ct.Name, "Textbox") > 0 Then
            tmpcben = tmpcben & ct & "|"
            ct = ""
        End If
    Next
    tmpfmen = Left(tmpfmen, Len(tmpfmen) - 1)
    tmpcben = Left(tmpcben, Len(tmpcben) - 1)
    tmpheader = header
    tmpmysht = mySheet
    headerArr = Split(header, ",")
    tmpwken = ""
    Set sht = Worksheets(mySheet)
    For a = 0 To (UBound(headerArr) - 1) / 2
        tmpwken = tmpwken & sht.Range(headerArr(a * 2)) & "|"
        sht.Range(headerArr(a * 2)) = ""
    Next
    tmpwken = Left(tmpwken, Len(tmpwken) - 1)
    CmdUndo.Enabled = True
End Sub
Private Sub CmdUndo_Click()
    fmen = Split(tmpfmen, "|")
    cben = Split(tmpcben, "|")
    Dim ctl                   As Control
    For Each ctl In Me.Controls
        If InStr(ctl.Name, "TextBox") Then
            ctl.Text = fmen(n)
            n = n + 1
        ElseIf InStr(ctl.Name, "Textbox") Then
            ctl.Text = cben(m)
            m = m + 1
        End If
    Next
    headre = tmpheader
    mySheet1 = tmpmysht
    headerArr = Split(headre, ",")
    wken = Split(tmpwken, "|")
    Set sht = Worksheets(mySheet1)
    For a = 0 To (UBound(headerArr) - 1) / 2
        sht.Range(headerArr(a * 2)) = wken(n2)
        n2 = n2 + 1
    Next
    CmdUndo.Enabled = False
    tmpfmen = ""
    tmpcben = ""
    tmpwken = ""
End Sub
Private Sub UserForm_Initialize()
    If tmpfmen = "" And tmpwken = "" Then
        CmdUndo.Enabled = False
    Else
        CmdUndo.Enabled = True
    End If
End Sub
Private Sub CmdCancel_Click()
    UnloadMe
End Sub
Private Sub CmdExit_Click()
    ThisWorkbook.Saved = True
    ThisWorkbook.Close
End Sub
Private Sub CommandButton1_Click()
    If UBound(headerArr) Mod 2 <> 1 Then MsgBox "Error in Cell Address & Header pair"
    For a = 0 To (UBound(headerArr) - 1) / 2
        Range(headerArr(a * 2)).Offset(0, 1) = InputBox(headerArr(a * 2 + 1), "Field Entry")
    Next
End Sub
Private Sub cmdOK_Click()
    headerArr = Split(header, ",")
    Set sht = Worksheets(mySheet)
    For a = 0 To (UBound(headerArr) - 1) / 2
        sht.Range(headerArr(a * 2)) = Controls("TextBox" & (a + 1))
    Next
End Sub
Private Sub cmdPrint_Click()
    ActiveSheet.PrintOut copies:=1
End Sub
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Oh just for clarification... the textbox1 is actually a combobox. I just rename it to textbox1.
Tnx
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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