I have en Excel List with ID's and Data(About 8000 Rows and more). The ID's can be only digits oder Digits with charaters. Like "2222222222222223" or "222222222222222A" (the Cells with the ID are formatted as Text)
If i try to find the Entry Address with a ID, it will insert a now row, because it will not find them. What means that at the End i have Doubled all Entries.
So my Question is, how many characters does the find method compare?
With objSheet
strAdresseExcel = .Cells.Find(What:=str, After:=.Cells(1, 1), _
LookAt:=Excel.XlLookAt.xlWhole, MatchCase:=True, SearchFormat:=False).Address
End with
So i created a dummy List with 8000 Rows where all the ID's had the Number "2222222222222222" and i found something out.
That Excel compares only the first 15 characters if there are only Digits in the String but i works fine if there is a Letter in the ID! You can see the issue in the Image below
Information to the Image:
Row A:
i worked with Conditional Formatting.
(On the Home tab, click Conditional Formatting, Highlight Cells Rules, Duplicate Values)
Works only when the ID has Digits or there is a difference in the first 15 Characters.
Row B:
I worked with a Formula. (=IF(COUNTIF(A:A;A2)>1;"Double";""))
How you can see, the same Problem happens here as well.
FIND Function of VBA Excel. The FIND function of VBA excel searches a specific value in a specified range. It looks for the first instance of such value and if a match is found, the function returns the cell containing it. However, if a match is not found, the function does not return anything.
Remarks. This method returns Nothing if no match is found. The Find method does not affect the selection or the active cell. The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method.
LEFT Function (Worksheet / VBA) The LEFT function returns the specified number of characters in a text string, starting from the first or left-most character. Use this function to extract a sub-string from the left part of a text string.
This seems to work for me, unless I'm missing something, which is entirely possible :)
It returns the first address where the cell matched and prints out the lengths of the strings searched. I have the data set setup in Sheet1 just as shown, with the numeric data being stored as Text (I added an apostrophe at the start of each value)
Sub testSO()
Dim objSheet As Worksheet: Set objSheet = ThisWorkbook.Sheets("Sheet1")
Dim strToFind As String: strToFind = "22222222222222222222222"
Dim strAddress As String
strAddress = objSheet.Cells.Find(strToFind, objSheet.Cells(1, 1), _
LookAt:=Excel.XlLookAt.xlWhole, MatchCase:=True, SearchFormat:=False).Address
'Print out findings
Debug.Print strAddress, Len(strToFind), Len(objSheet.Range(strAddress))
End Sub
Output is:
$A$5 23 23
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With