Results 1 to 5 of 5

Thread: vba excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3

    vba excel

    working on a search of excel wrkbk, with a user form out front. would rather be doing it in access but need to keep it thin for distribution. Having problems trying to deeal with partial search entries, looking for n1234abc but enter n1234, want to bring up all that contain the partial if someone does't know the whole part number or if they enter it wrong.

    any ideas would be greatly appreciated

    been trying to do it in VBA.

  2. #2
    Member
    Join Date
    Aug 2001
    Location
    Eugene, Oregon
    Posts
    41
    I have not dealt with Excel much but I can help you with the partial entry.

    Say they are searching for n1234 and the string you are searching is n1234abc. You could do this:

    Dim testlike

    testlike = "n1234abc" Like "*n1234*"

    If testlike = True Then
    MsgBox ("we have a match")
    Else
    MsgBox ("no match")
    End If

    Hope that helps.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3

    vab excel

    Thank you fro your help, That may not be the exact way but you gave me some ideas and got me going in another direction,


    thank you very much.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Omaha, NE
    Posts
    270
    To test this code, open a new workbook, add a UserForm with 2 textboxes & 1 command button to this workbook (leaving the names defaulted), and paste this code into UserForm code window. Add a module & put add a macro to show the userform.

    Enter data on the worksheet & run the macro.
    VB Code:
    1. Option Explicit
    2. Private strFirstCell As String
    3.  
    4. Private Sub CommandButton1_Click()
    5.     Static c
    6.    
    7.     Sheets("Sheet1").Select
    8.     If CommandButton1.Caption = "Find" Then
    9.         Range("A1").Select
    10.         strFirstCell = ""
    11.         Set c = Cells.Find(What:=TextBox1.Text, LookIn:=xlValues, LookAt:=xlPart, _
    12.             MatchCase:=False)
    13.         If Not c Is Nothing Then
    14.             c.Select
    15.             strFirstCell = ActiveCell.Address
    16.             TextBox2.Text = c.Value
    17.             CommandButton1.Caption = "Find Next"
    18.         End If
    19.     Else
    20.         Set c = Cells.FindNext(After:=ActiveCell)
    21.         If Not c Is Nothing Then
    22.             c.Select
    23.             If ActiveCell.Address = strFirstCell Then
    24.                 MsgBox "All partial strings found."
    25.                 CommandButton1.Caption = "Find"
    26.             Else
    27.                 TextBox2.Text = c.Value
    28.             End If
    29.         End If
    30.     End If
    31. End Sub
    Hope this helps.
    Nate

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3

    vba excel

    Thank you very much for your help, with a little tweaking I believe this could be the answer to my prayers. Thank you for taking the time to help me it is greatly appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width