hier mal im Anhang eine Test Datei.
Es sind mehrere ablagen und zwischen den soll der wechsel stattfinden.
https://www.herber.de/bbs/user/137023.xlsx
Für eine Lösung wäre ich sehr dankbar.
Gruß
Ralf
Option Explicit
Public erste As String, zweite As String, ersteformel As String, zweiteformel As String
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("D3:G10,I3:L10,N3:Q10,D14:G21,I14:L21,N14:Q21")) Is Nothing Then
Cancel = True
If erste = "" Then
erste = Target.Address
ersteformel = Target.Cells(1).Formula
End If
zweite = Target.Address
zweiteformel = Target.Cells(1).Formula
If erste zweite And zweite "" Then
Application.EnableEvents = False
Range(erste).Cells(1).Formula = zweiteformel
Range(zweite).Cells(1).Formula = ersteformel
erste = ""
zweite = ""
Application.EnableEvents = True
End If
End If
End Sub
Wo genau muß das hin?Public erste As String, zweite As String, ersteformel As String, zweiteformel As String
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("D3:G10,I3:L10,N3:Q10,D14:G21,I14:L21,N14:Q21")) Is Nothing Then
ActiveSheet.Unprotect Password:="hallo"
Cancel = True
If erste = "" Then
erste = Target.Address
ersteformel = Target.Cells(1).Formula
End If
zweite = Target.Address
zweiteformel = Target.Cells(1).Formula
If erste zweite And zweite "" Then
Application.EnableEvents = False
Range(erste).Cells(1).Formula = zweiteformel
Range(zweite).Cells(1).Formula = ersteformel
erste = ""
zweite = ""
Application.EnableEvents = True
End If
ActiveSheet.Protect Password:="hallo"
End If
End Sub
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Interior.ColorIndex = 3 Then
ActiveCell.Interior.ColorIndex = xlNone
Else
ActiveCell.Interior.ColorIndex = 3
End If
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Interior.ColorIndex xlNone Then
OldColor = ActiveCell.Interior.ColorIndex
ActiveCell.Interior.ColorIndex = xlNone
Else
ActiveCell.Interior.ColorIndex = OldColor
End If
End Sub
Option Explicit
Public OldColor
In der Variable OldColor wird die Farbe der Zelle gespeichert die Du doppelklickstConst Bereich As String = "D3:G10,I3:L10,N3:Q10,D14:G21,I14:L21,N14:Q21"
Public erste As String, zweite As String, ersteformel As String, zweiteformel As String
Public Farbe1, Farbe2
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range(Bereich)) Is Nothing Then
ActiveSheet.Unprotect Password:="hallo"
Cancel = True
If erste = "" Then
erste = Target.Address
ersteformel = Target.Cells(1).Formula
Farbe1 = Target.Cells(1).Interior.Color
End If
zweite = Target.Address
zweiteformel = Target.Cells(1).Formula
Farbe2 = Target.Cells(1).Interior.Color
If erste zweite And zweite "" Then
Application.EnableEvents = False
Range(erste).Cells(1).Formula = zweiteformel
Range(erste).Cells(1).Interior.Color = Farbe2
Range(zweite).Cells(1).Formula = ersteformel
Range(zweite).Cells(1).Interior.Color = Farbe1
erste = ""
zweite = ""
Farbe1 = -4142
Farbe2 = -4142
Application.EnableEvents = True
End If
ActiveSheet.Protect Password:="hallo"
End If
End Sub
Const Bereich As String = "D3:G10,I3:L10,N3:Q10,D14:G21,I14:L21,N14:Q21"
Public erste As String, zweite As String, ersteformel As String, zweiteformel As String
Public Farbe1, Farbe2
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range(Bereich)) Is Nothing Then
ActiveSheet.Unprotect Password:="hallo"
Cancel = True
If erste = "" Then
erste = Target.Address
ersteformel = Target.Cells(1).Formula
Farbe1 = Target.Cells(1).Interior.Color
End If
zweite = Target.Address
zweiteformel = Target.Cells(1).Formula
Farbe2 = Target.Cells(1).Interior.Color
If erste zweite And zweite "" Then
Application.EnableEvents = False
Range(erste).Cells(1).Formula = zweiteformel
Range(erste).Cells(1).Interior.Color = Farbe2
Range(zweite).Cells(1).Formula = ersteformel
Range(zweite).Cells(1).Interior.Color = Farbe1
erste = ""
zweite = ""
Farbe1 = -4142
Farbe2 = -4142
Application.EnableEvents = True
End If
ActiveSheet.Protect Password:="hallo"
End If
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range(Bereich)) Is Nothing Then
ActiveSheet.Unprotect Password:="hallo"
Cancel = True
With Target.Cells(1)
If .Interior.ColorIndex = -4142 Then
.Interior.Color = vbRed
Else
.Interior.Color = IIf(.Interior.Color = vbRed, vbGreen, vbRed)
End If
End With
ActiveSheet.Protect Password:="hallo"
End If
End Sub
If erste zweite And zweite "" Then
ActiveSheet.Unprotect
Application.EnableEvents = False
Range(erste).Cells(1).Formula = zweiteformel
Range(zweite).Cells(1).Formula = ersteformel
erste = ""
zweite = ""
Application.EnableEvents = True
ActiveSheet.Protect
End If