Insert double-click code into existing macro

Jdadad23

New Member
Joined
Dec 14, 2016
Messages
11
Hello,

I have a report I generate daily to check past work which I have been manually formatting for a few months -- the last thing I do when formatting is use a double click macro so I can double click a cell and it will change the cell color so I know I have already looked at that line. Well I finally put all the formatting into a macro, however I can't seem to add the double click portion of it. Here is the macro I created:

Code:
Sub EC_FreightLog()
'
' EC_FreightLog Macro
' Formats the freight log
'
With ActiveSheet
    .AutoFilterMode = False
    With Range("G1", Range("G" & Rows.Count).End(xlUp))
        .AutoFilter 1, "*TK*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    .AutoFilterMode = False
End With
    Cells.Select
    ActiveWorkbook.Worksheets("rep01034866").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("rep01034866").Sort.SortFields.Add Key:=Range( _
        "A2:A105"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("rep01034866").Sort
        .SetRange Range("A1:R105")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Columns("C:C").Select
    Selection.Delete Shift:=xlToLeft
    Columns("K:M").Select
    Selection.Delete Shift:=xlToLeft
    Columns("N:N").Select
    Selection.Delete Shift:=xlToLeft
    Cells.Select
    Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(9), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$M$200").AutoFilter Field:=3, Criteria1:="="
    Range("I4:I139").Select
    Range("I139").Activate
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 5296274
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Selection.AutoFilter
    Columns("A:M").Select
    Columns("A:M").EntireColumn.AutoFit
End Sub

And here is what I would like to add to it:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Interior.ColorIndex = 3
End Sub

I know I can't start a new sub within a sub so I remove those but I still can't seem to get this to run. Any way I have tried to rewrite it with my limited vba knowledge, I either get a compile error or a syntax error. Help is appreciated

*Edit
This part of the code is just a max range I think I would need to fill all the data, but the range I really need is just cells with data in them. So it could be 50 rows or 132 rows, I just don't know how to put that into code, if someone would like to help with that as well, it would be an added bonus.
Code:
ActiveSheet.Range("$A$1:$M$200").AutoFilter Field:=3, Criteria1:="="    
Range("I4:I139").Select
Range("I139").Activate
 
Last edited:
Unless i'm missing something, you just need to place your second chunk of code in the sheet object, you may have it in the this workbook object. If you need this action to occur on many sheets just add that code to each sheet object?
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top