autofill textbox??

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
349
Office Version
  1. 365
Platform
  1. Windows
I have a userform which is used for some basic data entry. One of the fields is for location. when the form is executed it simply enters the data into a list format where the location texbox data is in column B.


since the locations wil be repeated many times I want to make sure that spelling is consistant. Is there a way to perform an auto fill function on the text box. For instance, if the data in column B was


san Jose
Los Angeles
Napa valley
Las vegas
New York....

when the user started typing "N" the form would fill in "Napa Valley" but then if they entered "Ne" it would change to "New York". This is something similar to what Google autocomplete does?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
you could create a drop down bar which should work for you, then the text should be recognised as you type. there are some simple instructions online to create one.
 
Upvote 0
If I use a drop down can I create a new location that is not previously in the list?
 
Upvote 0
What would be the easiest way to populate the dropdown. I know I can do a loop to populate the dropdown with the entire column of data but how can I do it adding only unique values?
 
Upvote 0
Create another tab or list on the sheet and use Data Validation in Excel, then just allow yourself enough blank rows so the drop down will add the city name as you add them to the list.
 
Upvote 0
PCride,

I am not following what you are suggesting? I am trying to do this on a userform. I can use a combobox(dropdown) to do as previously suggested and I can use a loop to populate the combobox. I just do not want 100's of duplicate entries. I don't want to make this overly complicated so I prefer not to add any additional columns or worksheets if possible.
 
Upvote 0
I figured out a solution after playing with some code. It may not be the most elegant method but it works.

I call out this sub on initialization of the userform and then again anytime that I update the data on the spreadsheet. This way I will always have the most upto date information in the combobox.


Code:
Private Sub update_store()
Dim ws As Worksheet
Dim store_name() As String
Set ws = Worksheets("sheet1")
 
' gets last populated row in column 4 
irow = ws.Cells(Rows.Count, 4).End(xlUp).Row + 1
 
'initializes array length
fcount = 0
 
'defines array
ReDim Preserve store_name(0 To 1) 
store_name(0) = ""
 
'loops through all rows to search for unique values
For x = 2 To irow 
    y = 0
 
' loops through list of unique values stored in array
    Do While y <= fcount 
 
'tests to see of value already stored
        If ws.Cells(x, 4) <> store_name(y) Then 
 
'store value only if checked all saved values
            If y = fcount Then 
 
' increases array size
                ReDim Preserve store_name(0 To fcount + 1) 
 
' stores new value to array
                store_name(fcount) = ws.Cells(x, 4) 
 
' causes loop for exit
                y = y + 2
 
'increase count of array size 
                fcount = fcount + 1
            End If
 
'exits loop if value present
        Else: Exit Do
 
 
        End If
        y = y + 1
     Loop
Next x
 
' clears current values of combobox
me.store.clear 
 
' writes new values to combobox 
For z = 0 To fcount 
With Me.store
        .AddItem store_name(z)
End With
Next z
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,562
Members
449,171
Latest member
jominadeo

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