+ Reply to Thread
Results 1 to 21 of 21

how to do a vague look-up

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    how to do a vague look-up

    Hi,
    I tried to write the attached the code for a vague look-up and then copy the relevant info to the blank space, but it pop-up the error showed "compile error: Expected Expression"
    dose someone can help to see which line I did not write properly?
    thks.
    Capture.JPG
    Attached Files Attached Files

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to do a vague look-up

    Hi,

    You are not allowed to use Name as the name of a routine. You need only change that to something else, and edit your Like line
    If c.Value Like "*" & strSearch4 & "*" Then
    rather than
    If c.Value Like "*" & "strSearch4" & "*" Then
    Last edited by xlnitwit; 10-05-2016 at 04:57 AM.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: how to do a vague look-up

    Public Sub Name()
    Dim strSearch4 As String, c As Range, i As Long, counter As Long
    Application.ScreenUpdating = False
    counter = 0
    strSearch4 = "*" & Worksheets(3).TextBox2.Value & "*"
    For i = 10 To Sheets.Count
        For Each c In Sheets(i).Range("C1:C100")
            If c.Value Like strSearch4 Then
                counter = counter + 1
                c.Resize(, 3).Copy Sheets(3).Range("G" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next
    Next
    If counter = 0 Then
        MsgBox "no info found, check the input"
    End If
    Application.ScreenUpdating = True
    End Sub
    Kind regards
    Leo

  4. #4
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    I tried ur code, but it displayed compile error again.

  5. #5
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: how to do a vague look-up

    It runs in file you posted


    Kind regards
    Leo
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    thks for the help.
    I ran it again and it is Ok.
    But I tried to look up the model# and copy the entire row and I changed some of codes.
    unfortunately, when run the code, it showed "object variable or with block variable not set"
    does it mean if there sth. I dun define properly?
    Attached Files Attached Files

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to do a vague look-up

    @VBAidiot
    Change the name of the procedure to something besides Name. notName for example.

  8. #8
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi xlnitwit,
    thks for reminder

  9. #9
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: how to do a vague look-up

    Cod for search with textbox2

    Public Sub Text_Box_2()
    Dim strSearch4 As String, c As Range, i As Long, counter As Long, hs As Long
    Application.ScreenUpdating = False
    Sheets(3).Range("G:J").ClearContents
    counter = 0
    strSearch4 = "*" & Worksheets(3).TextBox2.Value & "*"
    For i = 10 To Sheets.Count
        For Each c In Sheets(i).Range("F1:F100")
            If c.Value Like strSearch4 Then
                counter = counter + 1
               c.Offset(, -3).Resize(, 4).Copy Range("G" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next
    Next
    If counter = 0 Then
        MsgBox "no info found, check the input"
    End If
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Leo

  10. #10
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    Thks for helping me to solve the problem again.
    however, for the model searching, I do not want to come out too many results.
    e.g, for 8157, since I knew there is 8157A, 8157B & 8157C, I just wanna these results but not 81577A.
    so I hope when I input 8157X, that means the only one I am not sure is in "X" part, and after searching I can get the 8157A/B/C result but not the items like 81577A
    thks.
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how to do a vague look-up

    Quote Originally Posted by VBAidot View Post
    e.g, for 8157, since I knew there is 8157A, 8157B & 8157C, I just wanna these results but not 81577A.
    so I hope when I input 8157X, that means the only one I am not sure is in "X" part, and after searching I can get the 8157A/B/C result but not the items like 81577A
     Public Sub test()
        Dim strSearch4 As String, k
        Dim c As Range
        Dim hs As Long
        Dim i As Long, counter As Long
        Application.ScreenUpdating = False
        k = Worksheets.Count
        strSearch4 = Worksheets(3).TextBox2.Value
        For i = 10 To k
           For Each c In Sheets(i).Range("C1:C100")
            If c.Value Like "*" & strSearch4 & "[BC]" Then
                counter = 1
                c.EntireRow.Copy Sheets(3).Range("G" & Rows.Count).End(xlUp)(2)
            End If
          Next
        Next
        If counter = 0 Then
            MsgBox "no info found, check the input"
        End If
        Application.ScreenUpdating = True
    End Sub

  12. #12
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    HI Jindon,
    thks for replying.
    But ,since I need to search the model#, so I changed the range from ("C1:C100") to (F1:F100) and input the 8157 into textbox2 and run the code, it showed "compile error"

  13. #13
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Jindon,
    I tried ur code and changed the range from (C1:C100) to (F1:F100) since I will search the model#, it also appeared "compile error"
    could you pls help to check ?
    thks.

  14. #14
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    run by exit the textbox, it is okay.
    Appreciations.
    Last edited by VBAidot; 10-13-2016 at 10:25 PM.

  15. #15
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: how to do a vague look-up

    Only 8157 in textbox2

    Public Sub Text_Box_2()
    Dim strSearch4 As String, c As Range, i As Long, counter As Long, hs As Long
    Application.ScreenUpdating = False
    Sheets(3).Range("G:J").ClearContents
    counter = 0
    strSearch4 = "*" & Worksheets(3).TextBox2.Value & "?"
    For i = 10 To Sheets.Count
        For Each c In Sheets(i).Range("F1:F100")
            If c.Value Like strSearch4 Then
                counter = counter + 1
               c.Offset(, -3).Resize(, 4).Copy Range("G" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next
    Next
    If counter = 0 Then
        MsgBox "no info found, check the input"
    End If
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Leo

  16. #16
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    I input the 8157 in textbox2 & run the code, it showed the "compile error"

  17. #17
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    I input the 8157 in textbox2 & run the code, it showed the "compile error"[/QUOTE]

  18. #18
    Registered User
    Join Date
    09-27-2014
    Location
    Africa
    MS-Off Ver
    2013
    Posts
    50

    Re: how to do a vague look-up

    Hi Leo,
    I input 8157 in textbox2 & run the code, it showed "compile error"

  19. #19
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: how to do a vague look-up

    I dont have the error, so i have to compere the files

    Kind regards
    Leo

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how to do a vague look-up

    Try the attached
    Sub test()
        Dim strSearch4 As String, k
        Dim c As Range
        Dim hs As Long
        Dim i As Long, counter As Long
        Application.ScreenUpdating = False
        k = Worksheets.Count
        Sheets(3).[g1].CurrentRegion.Offset(1).Clear
        strSearch4 = Worksheets(3).TextBox2.Value
        For i = 10 To k
           For Each c In Sheets(i).Range("F1:F100")
            If c.Value Like "*" & strSearch4 & "[BC]" Then
                counter = 1
                c(, -2).Resize(, 4).Copy Sheets(3).Range("G" & Rows.Count).End(xlUp)(2)
            End If
          Next
        Next
        If counter = 0 Then
            MsgBox "no info found, check the input"
        End If
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

  21. #21
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: how to do a vague look-up

    Code runs by exit textbox

    Private Sub TextBox2_LostFocus()
    Dim strSearch4 As String, c As Range, i As Long, counter As Long, hs As Long
    Application.ScreenUpdating = False
    Sheets(3).Range("G1").CurrentRegion.Offset(1).ClearContents
    counter = 0
    strSearch4 = "*" & Worksheets(3).TextBox2.Value & "?"
    For i = 10 To Sheets.Count
        For Each c In Sheets(i).Range("F1:F100")
            If c.Value Like strSearch4 Then
                counter = counter + 1
               c.Offset(, -3).Resize(, 4).Copy Range("G" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next
    Next
    If counter = 0 Then
        MsgBox "no info found, check the input"
    End If
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Leo
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I use the "Proper" function? The instructions are vague.
    By DaveB in forum Excel Formulas & Functions
    Replies: 30
    Last Post: 09-06-2005, 07:05 PM
  2. [SOLVED] How do I use the "Proper" function? The instructions are vague.
    By Polly in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  3. How do I use the "Proper" function? The instructions are vague.
    By DaveB in forum Excel Formulas & Functions
    Replies: 25
    Last Post: 09-06-2005, 05:05 PM
  4. How do I use the "Proper" function? The instructions are vague.
    By Polly in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  5. How do I use the "Proper" function? The instructions are vague.
    By Polly in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  6. How do I use the "Proper" function? The instructions are vague.
    By Polly in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. How do I use the "Proper" function? The instructions are vague.
    By Polly in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1