It's all in the details.........I need a refresher every day....
It's all in the details.........I need a refresher every day....
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Thanks to Lucas, XLD, mdmackillop, thomaspatton, mikerickson, you guys are very talented. this is the final code adapted to may project, it toggles the color cells on and off including the date cells.
Thanks Team!
[vba]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
With Target
If .Column = 4 Then
If .Interior.ColorIndex = 4 Then
.Interior.ColorIndex = xlNone
Else
.Interior.ColorIndex = 4
End If
ElseIf .Column = 5 Then
If .Interior.ColorIndex = 3 Then
.Interior.ColorIndex = xlNone
Else
.Interior.ColorIndex = 3
End If
ElseIf .Column = 6 Then
If .Interior.ColorIndex = 6 Then
.Interior.ColorIndex = xlNone
Else
.Interior.ColorIndex = 6
End If
ElseIf .Column = 7 Then
If .Interior.ColorIndex = 5 Then
.Interior.ColorIndex = xlNone
Else
.Interior.ColorIndex = 5
End If
ElseIf .Column = 8 Then
If .Interior.ColorIndex = 7 Then
.Interior.ColorIndex = xlNone
Else
.Interior.ColorIndex = 7
End If
ElseIf .Column = 3 Then
If .Value = "" Then
.Value = Format(Date, "mmmm.d.yyyy")
Else
.Value = ""
End If
End If
End With
Cancel = True
End Sub[/vba]
Edit Lucas: Jose, I deleted the duplicate post....
Pass the values to a sub routine. It's more flexible and easirer to maintain
[vba]
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Select Case Target.Column
Case 4
DoColour Target, 4
Case 5
DoColour Target, 3
Case 6
DoColour Target, 6
Case 7
DoColour Target, 5
Case 8
DoColour Target, 7
Case 3
If Target.Value = "" Then
Target.Value = Format(Date, "mmmm.d.yyyy")
Else
Target.Value = ""
End If
End Select
Cancel = True
End Sub
Sub DoColour(Target As Range, Col As Long)
With Target
If .Interior.ColorIndex = Col Then
.Interior.ColorIndex = xlNone
Else
.Interior.ColorIndex = Col
End If
End With
End Sub
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'