Autocomplete cells

johntiber

New Member
Joined
Dec 20, 2010
Messages
1
Hi.
In column "A" I'm scriving values, for example prices.
I would like to do it faster. I found VBA code (unfortunately don't know author) which helps me much.
I have list of prices, for example 2,99 3,99 etc.
When I scive "2" or "3" and hit enter, vba automatically insert "2,99" "3,99"
Problem is when I have prices for example 2,99 and 22,99.
I would like to scrive 2,9 or 22,9 and let vba to fill rest but doesn't recognize ","
Is there any solution or other code which will serve it?



Private Sub Worksheet_Change(ByVal Target As Range)
'Sub "autocompletes" data entered into column A using a source table on a different worksheet. If more than one match is
' found, the user is allowed to continue entering characters until a unique match is found. If no matches are found, the
' data is accepted as entered. ALT + Enter, Enter to force the macro to accept data as entered. The sub is triggered by
' the Enter key.
Dim cel As Range
Dim match1 As Range
Dim match2 As Range
Dim rg As Range
Dim targ As Range

'***Please adjust the next two statements before using this code!***
Set targ = Intersect(Target, Range("A:A")) 'Watch the cells in column A
Set rg = Worksheets("Source data").Range("B:B") 'Use named range AutoCompleteText for "autocomplete" info

If targ Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error GoTo errhandler 'If code encounters an error, turn events back on

For Each cel In targ
If Not IsError(cel) Then
If cel <> "" And Right(cel, 3) <> Chr(10) Then
Set match1 = Nothing
Set match1 = rg.Find(cel & "*", lookat:=xlWhole, MatchCase:=False) 'Match is case insensitive
If Not match1 Is Nothing Then
Set match2 = rg.FindNext(after:=match1)
If match2.Address = match1.Address Then 'Code is fooled by identical strings in two cells
cel = match1 'Only one match found. Use it to "autocomplete" the cell
Else 'More than one match found. User must enter more data. Return to "Edit" mode
cel.Activate
'Application.SendKeys ("{F2}") 'Begin editing after last character entered
End If
Else 'No matches found. Do not change entered text
End If
Else 'Strip the line feed from the end of the text string
If cel <> "" And Right(cel, 3) = Chr(10) Then cel = Left(cel, Len(cel) - 1)
End If
End If
Next cel

errhandler: Application.EnableEvents = True
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Chaps. Sorry to resurect an old thread.
I've been looking for a method to auto complete and found this little snippet which works great, apart from:

The end user wouldn't know that this data exists until they press enter.
If the data exists, then the sheet is populated with the correct info.

ie.
Lets say the name Smith exists in Source data.
When the user types Smi on the workingsheet, and presses enter, the cell is now populated with "Smith".
However, if Smith does not exists in Source data, then the cell would be populated with Smi.

So I'm looking for some method of auto complete which works like the Standard auto complete, whereby the cell is pupulated with the full details before you press enter.

I guess it's complex, but af anyone has any other ideas or pointers, i'd welcome them.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,380
Messages
6,130,274
Members
449,570
Latest member
TomMacca52

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