Sub test()
Dim meAr
Dim strText$
'Kommentar auslesen in einen String
strText = Range("B1").Comment.Text
If InStr(strText, Chr(10)) > 0 Then
meAr = Split(strText, Chr(10))
End If
'ab A2 leer machen für neue Daten (A1= Überschrift)
Range("A2").Resize(Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
If IsArray(meAr) Then
Range("A2").Resize(Ubound(meAr) + 1) = Application.Transpose(meAr)
Else
Range("A2") = strText
End If
End Sub
Gruß TinoSub KommentarZurueck()
Dim meAr
Dim strText$
'Bereich mit den Daten
meAr = Range("A2", Cells(Rows.Count, 1).End(xlUp))
'Text zusammenführen
If IsArray(meAr) Then
With Application
strText = Join(.Transpose(meAr), Chr(10))
End With
Else
strText = meAr
End If
'Text in Kommentar schreiben
Range("B1").Comment.Text Text:=strText
End Sub
Gruß TinoE | |
21 | Zeile1 12 23 Zeile4 |
22 | Zeile1 12 23 Zeile4 |
Sub ArTrenneTextZahl(strText$, meAr)
Dim objMatch As Object, objRegEx As Object
Dim A As Long
Set objRegEx = CreateObject("VBScript.RegExp")
With objRegEx
.MultiLine = True
.Global = True
.IgnoreCase = True
.Pattern = "[0-9]{1,},?[0-9]{1,}"
Set objMatch = .Execute(strText)
End With
For Each objMatch In objMatch
strText = Replace(strText, objMatch, Chr(10) & objMatch & Chr(10))
Next objMatch
meAr = Split(strText, Chr(10))
End Sub
Sub test()
Dim meAr
Dim strText$
Dim A&
'Kommentar auslesen in einen String
strText = Range("B1").Comment.Text
If InStr(strText, Chr(10)) > 0 Then
ArTrenneTextZahl strText, meAr
End If
'ab A2 leer machen für neue Daten (A1= Überschrift)
Range("A2").Resize(Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
If IsArray(meAr) Then
Range("A2").Resize(Ubound(meAr) + 1) = Application.Transpose(meAr)
Else
Range("A2") = strText
End If
End Sub
Gruß TinoEnum EnumPattern
Zahlen_ = 0
Text_ = 1
End Enum
Sub ArTrenneTextZahl(strText$, meAr, sPattern As EnumPattern)
Dim objMatch As Object, objRegEx As Object
Dim A As Long, AA As Long, tmpAr()
Dim Korrektur As Long
Dim strPattern$
Const sZahlen$ = "[0-9]{1,},?[0-9]{0,}"
Const sText$ = "\D{2,}"
strPattern$ = IIf(sPattern = Text_, sText, sZahlen)
Set objRegEx = CreateObject("VBScript.RegExp")
With objRegEx
.MultiLine = True
.Global = True
.IgnoreCase = True
.Pattern = strPattern
Set objMatch = .Execute(strText)
End With
If Not objMatch Is Nothing Then
Redim Preserve tmpAr(objMatch.Count - 1)
For Each objMatch In objMatch
If IsNumeric(objMatch) Then
tmpAr(A) = objMatch * 1
Else
tmpAr(A) = objMatch
End If
A = A + 1
Next objMatch
End If
meAr = tmpAr
End Sub
Sub Test_Text_Zahlen_Trennen()
Dim meArText, meArZahlen
Dim strText$
Dim A&
'Kommentar auslesen in einen String
strText = Range("B1").Comment.Text
If (strText Like "*#*") Then
ArTrenneTextZahl strText, meArZahlen, Zahlen_
End If
If (strText Like "*[A-Z]*") Then
ArTrenneTextZahl strText, meArText, Text_
End If
'ab A2 leer machen für neue Daten (A1= Überschrift)
Range("A2").Resize(Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
Range("B2").Resize(Cells(Rows.Count, 2).End(xlUp).Row + 2).ClearContents
If IsArray(meArText) Then
Range("A2").Resize(Ubound(meArText) + 1) = Application.Transpose(meArText)
End If
If IsArray(meArZahlen) Then
Range("B2").Resize(Ubound(meArZahlen) + 1) = Application.Transpose(meArZahlen)
End If
End Sub
Gruß Tino