- AUTOCOMPLETE FROM ANOTHER WORKBOOK
According to the code from this thread I wanted to create similar code but in a source another workbook.
Workbook is in different location.
I have tried this modifications:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range, match1 As Range, match2 As Range, rg As Range, targ As Range
Dim filePath As String
filePath = "P:Projekty_ZakonczoneKOM PLIKILISTA KLIENTÓW.xlsx"
'***Please adjust the next two statements before using this code!***
Set targ = Intersect(Target, Range("E11"))
Set rg = Workbooks("filePath").Sheets("LISTA KLIENTÓW").Range("LISTAK")
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, 1) <> Chr(10) Then
Set match1 = Nothing
Set match1 = rg.Find(cel & "*", lookat:=xlPart, 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, 1) = 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
The error is always at the line: Set rg = Workbooks(“filePath”).Sheets(“LISTA KLIENTÓW”).Range(“LISTAK”)
Any Ideas?
- MULTIPLE AUTOCOMPLETES
And this one is beyond my knowledge.
In same Sheet I need actually two codes for two different range and two different sources.
First one is for E11 cell and with sourse in pilepath LISTA KLIENTÓW.xlsx.Range(“listak”) – like above.
Second one is for cells P4 till P30 with source in filepath LISTA STANOWISK.xlsx.Range(“listas”)
Could someone help to combine those two requests together?
According to MULTIPLE AUTOCOMPLETE: Any of my combinations fails. I have tried just simply copying whole sequence and changing all DIM names. Does not work.
I probably missing something in syntax.
Kompania Elektroniczna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.