Macro ausführung String länge
26.01.2023 23:49:56
Patrick
Ich habe auf der Arbeit ein Macro um Data Matrix Codes zu Scannen das mir diese dann in einer Formatierten Form ausgibt um sie leichter zu lesen.
Leider haben wir für verschiedene Kunden verschieden lange Codes, und ich wollte fragen ob jemand weis wie ich die ausführung des jeweiligen Macros von der String länge abhängig machen kann ?
In etwa wie --- if ( activ cell row ? ) Len(49) then ---- zb
Hier noch das Macro das wir benutzen. Hoffe jemand kann mir helfen. Freundliche Grüße Patrick
Sub Worksheet_Change
Dim KeyCells As Range
Set KeyCells = Range("b2:b100000")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
Zeile = ActiveCell.Row
Spalte = ActiveCell.Column
ActiveSheet.Unprotect Password:="xxxxx"
Scan = Cells(Zeile, 2).Value
Application.EnableEvents = False
If Left(Scan, 1) > "]" Then
Cells(Zeile, 2).Value = ""
Else
If Left(Scan, 1) = "]" Then
Strz0 = Left(Scan, 3) & " "
Scan = Mid(Scan, 4, 200)
Else
Strz0 = " "
End If
Strz1 = Mid(Scan, 1, 2) & " "
Gtin = Mid(Scan, 3, 14) & " "
Strz2 = Mid(Scan, 17, 2) & " "
Standort = Mid(Scan, 19, 3) & " "
Seri = Mid(Scan, 22, 10) & " "
Strz4 = Mid(Scan, 32, 2) & " "
Verfall = Mid(Scan, 34, 6) & " "
Strz5 = Mid(Scan, 40, 2) & " "
Batch = Mid(Scan, 42, 8) & " "
Strz6 = Mid(Scan, 50, 3) & " "
PortLaenderCode = Mid(Scan, 53, 200)
Cells(Zeile, 2).Value = Strz0 & Strz1 & Gtin & Strz2 & Standort & Seri & Strz4 & Verfall & Strz5 & Batch & Strz6 & PortLaenderCode
Cells(Zeile, 3).FormulaR1C1 = "=IF(ISERROR(TEXT(RC[-2]-R[-1]C[-2],""[hh]:mm"")),"""",TEXT(RC[-2]-R[-1]C[-2],""[hh]:mm""))"
Cells(Zeile, 1).Value = Now()
Cells(Zeile, 2).Locked = True
Cells(Zeile + 1, 2).Locked = False
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="xxxxxx"
Application.EnableEvents = True
ActiveWorkbook.Save
End If
End Sub
Anzeige