Consulting

Results 1 to 4 of 4

Thread: excel vba search text in range and retrieve results in a textbox

  1. #1

    excel vba search text in range and retrieve results in a textbox

    This macros is working, but I want to display results from a range D2:82 in text box without automatically redirection user to the located text. When it comes to VBA, I am a very basic user.I realize I may be asking a question already asked and answered in a different thread so I apologize about that. Help me please change my macros?
    Sub Button 1_Click()
    
    Res = InputBox("Who are you looking for?")    
    Set Rng = Worksheets("Level2").Range("B2:B82")'<<  The Sheet Name and Range to Search
    
    With Rng    
        Set MyChoice =.Find(What:=Res)
    
        IfNot MyChoice IsNothingThen    
            Application.Goto MyChoice    
        Else:GoTo ExitMyChoice
    
        EndIf
    
    EndWith    
    ExitSub
    
    ExitMyChoice:    
    MsgBox "Could Not Find "& Res
    
    EndSub
    Last edited by SamT; 09-13-2016 at 11:35 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    but I want to display results from a range D2:82 in text box
    Sub Button 1_Click() 
         
        Res = InputBox("Who are you looking for?") 
        Set Rng = Worksheets("Level2").Range("B2:B82") '<<  The Sheet Name and Range to Search
         
        With Rng 
            Set MyChoice =.Find(Res) 
             
            If Not MyChoice Is Nothing Then 
                MsgBox Res
            Else
               MsgBox "Could Not Find " & Res 
           EndIf 
                 
     EndSub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    run a macro:

    Compile error:
    Sub or Function not defined

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    endsub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

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