VBA Userform Search Function

aswestley

New Member
Joined
Oct 31, 2016
Messages
8
Hi All,

I'm brand new to VBA and due to my new job, i'm required to create a spreadsheet with userforms so personnel can't tamper with the initial data once i've entered it.

I am looking to create a userform where people can search via asset number, the form then autofills with the rest of the data in set textboxes.

I can't find anywhere details on how to create this. I can send the file to anyone that wants to take a look.

i want txtID to be the search box looking at column B on my spreadsheet.

TIA
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
That's a little harsh to expect someone new to come up with that solution (unless you put in your CV that you had VBA skills ;) )

While it's straight forward enough for anyone with vba knowledge it's not a quick thing to learn.

Apologies but I don't have time to write that as although it's relatively simple, it's not quick. If time is of the essence, Mr Excel has a (paid)consultancy service that I'm sure can help professionals achieve their solutions.
 
Upvote 0
That's a little harsh to expect someone new to come up with that solution (unless you put in your CV that you had VBA skills ;) )

While it's straight forward enough for anyone with vba knowledge it's not a quick thing to learn.

Apologies but I don't have time to write that as although it's relatively simple, it's not quick. If time is of the essence, Mr Excel has a (paid)consultancy service that I'm sure can help professionals achieve their solutions.

gallen, thanks for the advise something i will seriously be looking into. It is a little harsh but the company i work for, we are incorporated into a Communications department and i have spent the last 5 years working on telecomms systems only to be put in here temporarily haha.
 
Upvote 0
Hi,
at a basic level perhaps something like following will help you

Rich (BB code):
Private Sub FindRecord_Click()
    Dim Search As String
    Dim FoundCell As Range, SearchRange As Range
    
'search sheet change name as required
    Set SearchRange = Worksheets("Sheet1").Columns(2)
    
    Search = Me.TxtID.Text
    
    If Len(Search) = 0 Then Exit Sub
   
        Set FoundCell = SearchRange.Find(What:=Search, LookIn:=xlValues, LookAt:=xlWhole _
        , SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not FoundCell Is Nothing Then
        Me.TextBox1.Value = FoundCell.Value
        Me.TextBox2.Value = FoundCell.Offset(0, 1).Value
        Me.TextBox3.Value = FoundCell.Offset(0, 2).Value
    Else
    
        MsgBox Search & Chr(10) & "Record Not Found", 48, "Not Found"
    End If
End Sub

You will need to adjust code to meet specific project need but should get you started.

Dave
 
Last edited:
Upvote 0
Hi,
at a basic level perhaps something like following will help you

Rich (BB code):
Private Sub FindRecord_Click()
    Dim Search As String
    Dim FoundCell As Range, SearchRange As Range
    
'search sheet change name as required
    Set SearchRange = Worksheets("Sheet1").Columns(2)
    
    Search = Me.TxtID.Text
    
    If Len(Search) = 0 Then Exit Sub
   
        Set FoundCell = SearchRange.Find(What:=Search, LookIn:=xlValues, LookAt:=xlWhole _
        , SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not FoundCell Is Nothing Then
        Me.TextBox1.Value = FoundCell.Value
        Me.TextBox2.Value = FoundCell.Offset(0, 1).Value
        Me.TextBox3.Value = FoundCell.Offset(0, 2).Value
    Else
    
        MsgBox Search & Chr(10) & "Record Not Found", 48, "Not Found"
    End If
End Sub

You will need to adjust code to meet specific project need but should get you started.

Dave

Dave, thats great thank you so much i'll give it a go.
 
Upvote 0

Forum statistics

Threads
1,223,843
Messages
6,174,982
Members
452,598
Latest member
jeffreyp

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