Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 23 of 23

Thread: Solved: Range cell color by Double Clicking

  1. #21
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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

  2. #22
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    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....

  3. #23
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •