Jörg: Excel: suche nach Zahl in Textzelle

Beitrag lesen

Hallo paula,

R36/38: R36/38 Irritating to eyes and skin.;R51/53: R51/53 Toxic to aquatic organisms, may cause long-term adverse effects in the aquatic environment.

Diese Angaben stehen so in EINER Zelle.

hier ist eine von vielen Möglichkeiten per VBA:

Sub Aufteilen()  
Dim lngZ As Long, lngLZ As Long  
Dim intS As Integer  
Dim strText As String, strTemp As String  
Dim arrTemp  
  
'Letzte ausgefüllte Zelle in Spalte 1 suchen:  
lngLZ = Cells(Rows.Count, 1).End(xlUp).Row  
  
'Von Zeile 2 bis zur letzten ausgefüllten Zelle in Spalte A durchlaufen:  
For lngZ = 2 To lngLZ  
    strText = Cells(lngZ, 1)  
  
    'Wenn ein Doppelpunkt enthalten ist:  
    If InStr(1, strText, ": ") > 0 Then  
  
        If InStr(1, strText, ".;") = 0 Then  
            'Wenn nur ein Satz enthalten ist:  
            Cells(lngZ, 2) = R_Extract(strText)  
        Else  
            'Bei mehreren Sätzen:  
            arrTemp = Split(strText, ".;")  
  
            strTemp = ""  
            For intS = 0 To UBound(arrTemp)  
                If intS = 0 Then  
                    strTemp = R_Extract(arrTemp(intS))  
                Else  
                    strTemp = strTemp & ";" & R_Extract(arrTemp(intS))  
                End If  
            Next  
            Cells(lngZ, 2) = strTemp  
        End If  
    End If  
Next  
End Sub  
  
  
  
Function R_Extract(ByVal strText As String)  
Dim arrTemp  
R_Extract = ""  
If strText = "" Then Exit Function  
If InStr(1, strText, ":") = 0 Then Exit Function  
  
arrTemp = Split(strText, ": ")  
  
R_Extract = arrTemp(0)  
End Function

Viele Grüße

Jörg