VBA lookup i can only enter numbers and not letters please help

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi i have the code below where it does a search but it will only let me enter numbers in the textbox and not letters, but i want to be able to input both numbers and letters can you help please, i am very new to VBA and still learning, i have searched for the answer alot on internet with no success so far, really hope you can help me.
Code:
Sub GetData()

If IsNumeric(UserForm1.TextBox1.Value) Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value
    
    Do While ThisWorkbook.Worksheets("Sheet2").Cells(i + 1, 1).Value <> ""
    
        If ThisWorkbook.Worksheets("Sheet2").Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                UserForm1.Controls("TextBox" & j).Value = ThisWorkbook.Worksheets("Sheet2").Cells(i + 1, j).Value
            Next j
        End If
        
        i = i + 1
        
    Loop
    
    If flag = False Then
        For j = 2 To 3
            UserForm1.Controls("TextBox" & j).Value = ""
        Next j
    End If
    
Else
    ClearForm
End If

End Sub
 
Last edited by a moderator:
https://www.dropbox.com/s/1eary58fewvtbcm/interactive-userform new.xlsm?dl=0

HIya again thank you for your patience, i have added the link to the spreadsheet i am working on, it will be a postcode lookup, for example the (some) postocdes are in sheet2, and when typed in the postcode textbox it will find the area and car and automatically load into the other 2 textboxs hope this makes sense? :) thank you again
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
It works perfectly for me.
Are you typing in upper or lower case letters?
 
Upvote 0
silly me, i was using lowercase
thank you again and patience you help has been amazing
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
For reference you can write the GetData sub like this
Code:
Sub GetData()
   Dim Rw As Variant
   If Len(UserForm1.TextBox1.Value) > 0 Then
      
      flag = False
      id = UserForm1.TextBox1.Value
      Rw = Application.Match(id, Sheets("Sheet2").Range("A2:A10"), 0)
      
      If Not IsError(Rw) Then
         flag = True
         For j = 2 To 3
            UserForm1.Controls("TextBox" & j).Value = ThisWorkbook.Worksheets("Sheet2").Cells(Rw, j).Value
         Next j
      End If
      
      If flag = False Then
         For j = 2 To 3
            UserForm1.Controls("TextBox" & j).Value = ""
         Next j
      End If
      
   Else
      ClearForm
   End If
End Sub
This eliminates 1 of the loops & also allows for lowercase letters.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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