AW: Zellbereich mit einer Zelle vergleichen
08.11.2006 13:53:15
Erich
Hallo Susi,
jetzt ist es wohl etwas klarer.
Kann es nicht vorkommen, dass im Blatt "Daten" Zeichenketten stehen, die wie ein Format aussehen, wie in TOR2311 ?
(Da fände das Makro jetzt das Format R23.)
So habe ich es jetzt verstanden:
Option Explicit
Sub test()
Dim rng As Range, rngF As Range, strAdr As String, strFor As String, strErg As String
Dim intP As Integer
strErg = "Neues Format"
' Suche erste Zelle mit "Rnn" (nn ist eine Ziffer) in Blatt "Daten"
With Worksheets("Daten")
Set rngF = .Cells.Find(What:="R?", After:=.Cells(1, 1), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not rngF Is Nothing Then
strAdr = rngF.Address
strFor = ""
Do
' Suche erste "Rnn" innerhalb der Zelle
intP = InStr(rngF, "R")
If intP > 0 And intP < Len(rngF) - 2 Then
If IsNumeric(Mid(rngF, intP + 1, 2)) Then
strFor = Mid(rngF, intP, 3) ' gefunden
Exit Do
End If
End If
Set rngF = .Cells.FindNext(rngF) ' weitersuchen
Loop While Not rngF Is Nothing And rngF.Address <> strAdr
End If
If strFor = "" Then
MsgBox "Kein Format gefunden in " & .Name
Exit Sub
End If
End With
' Suche gefundenes Format in Blatt "Format"
With Sheets("Format")
For Each rng In Range("B2:B7")
Set rngF = .Cells.Find(What:=strFor, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not rngF Is Nothing Then
strErg = strFor ' gefunden
Exit For
End If
Next rng
End With
MsgBox "Gesucht wurde: " & strFor & " - strErg hat den Wert '" & strErg & "'"
End Sub
Hier die Mappe zum Ausprobieren:
https://www.herber.de/bbs/user/37979.xls
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort