AW: Find hängt doch vom Format ab!
02.05.2008 18:33:12
Erich
Hi Sonnenpeter,
oft habe auch ich bisher behauptet, dass der Sucherfolg bei Find nur von den beteiligten Werten abhängt.
Durch deine Frage hab ich einmal mehr rumprobiert und das Ergebnis im Betreff bekommen.
Der folgende Code zeigt das:
Option Explicit
Sub TestFind()
Dim rngF As Range, lngZ As Long
Columns(2).Clear
Cells(5, 2).Formula = "=1.11/2"
DoIt xlWhole, lngZ
DoIt xlPart, lngZ
Cells(5, 2).NumberFormat = "0"
DoIt xlWhole, lngZ
DoIt xlPart, lngZ
Cells(5, 2).NumberFormat = "0.0"
DoIt xlWhole, lngZ
DoIt xlPart, lngZ
Cells(5, 2).NumberFormat = "0.00"
DoIt xlWhole, lngZ
DoIt xlPart, lngZ
Cells(5, 2).NumberFormat = "0.000"
DoIt xlWhole, lngZ
DoIt xlPart, lngZ
Cells(5, 2).NumberFormat = "0.0000"
DoIt xlWhole, lngZ
DoIt xlPart, lngZ
End Sub
Sub DoIt(enuWhole As XlLookAt, zz As Long)
Dim rngF As Range
Set rngF = Columns(2).Find(What:=Cells(5, 2).Value, After:=Cells(1, 2), LookIn:=xlValues, _
LookAt:=enuWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
zz = zz + 1
Cells(zz, 4) = "'" & Cells(5, 2).NumberFormat
Cells(zz, 5) = IIf(enuWhole = xlWhole, "xlWhole", "xlPart")
If rngF Is Nothing Then
Cells(zz, 6) = "Nein"
Else
Cells(zz, 6) = rngF.Address
End If
End Sub
Da kommt dabei heraus:
| B | C | D | E | F |
1 | | | General | xlWhole | $B$5 |
2 | | | General | xlPart | $B$5 |
3 | | | 0 | xlWhole | Nein |
4 | | | 0 | xlPart | Nein |
5 | 0,5550 | | 0.0 | xlWhole | Nein |
6 | | | 0.0 | xlPart | Nein |
7 | | | 0.00 | xlWhole | Nein |
8 | | | 0.00 | xlPart | Nein |
9 | | | 0.000 | xlWhole | $B$5 |
10 | | | 0.000 | xlPart | $B$5 |
11 | | | 0.0000 | xlWhole | Nein |
12 | | | 0.0000 | xlPart | $B$5 |
Und hier die Mappe zum Spielen: https://www.herber.de/bbs/user/52034.xls
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort