Normalerweise mache ich nix mit VBA in Excel. Wenn, dann kopiere ich nur Codes aus dem Internet.
Nun stehe ich vor dem Problem, dass ich zwei Worksheets-Change zusammenführen möchte, dies aber nicht schaffe.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim wert_old As String
Dim wertnew As String
On Error GoTo Errorhandling
If Not Application.Intersect(Target, Range("B4:B14")) Is Nothing Then
Set rngDV = Target.SpecialCells(xlCellTypeAllValidation)
If rngDV Is Nothing Then GoTo Errorhandling
If Not Application.Intersect(Target, rngDV) Is Nothing Then
Application.EnableEvents = False
wertnew = Target.Value
Application.Undo
wertold = Target.Value
Target.Value = wertnew
If wertold <> "" Then
If wertnew <> "" Then
Target.Value = wertold & ", " & wertnew
End If
End If
End If
Application.EnableEvents = True
End If
Errorhandling:
Application.EnableEvents = True
End Sub
Ich danke dir vielmals. dies mit den Code-Tags wusste ich nicht.
Ich kriegs leider nicht hin bzw. es kommt immer eine Fehlermeldung. Wo genau muss ich es einfügen und was alles?
Hat plötzlich doch geklappt
'#################################
'# Hier kommt die zweite Routine #
'#################################
Dim rngDV As Range
Dim wertold As String
Dim wertnew As String
On Error GoTo Errorhandling
If Not Application.Intersect(Target, Range("B4:B14")) Is Nothing Then
Set rngDV = Target.SpecialCells(xlCellTypeAllValidation)
If rngDV Is Nothing Then GoTo Errorhandling
If Not Application.Intersect(Target, rngDV) Is Nothing Then
Application.EnableEvents = False
wertnew = Target.Value
Application.Undo
wertold = Target.Value
Target.Value = wertnew
If wertold <> "" Then
If wertnew <> "" Then
Target.Value = wertold & ", " & wertnew
End If
End If
End If
Application.EnableEvents = True
End If
Errorhandling:
Application.EnableEvents = True
End Sub
Im übrigen war die Fehlermeldung wahrscheinlich die, dass die Variabe wertold nicht definiert ist. Die war nämlich als wert_old definiert. Ich habe das mal korrigiert.