# absent-minded coding



## erik.van.geit (Jun 2, 2013)

Very busy with different projects for a school...
Tried to solve a little problem without solving it 

```
Private Sub Workbook_Open()
Application.EnableEvents = True
End Sub
```
OK, this might be an inside joke, somebody else will perhaps take the time to explain if needed: till then it could be an enigma.

have a nice end of the weekend,
Erik


----------



## shg (Jun 2, 2013)

If events were not already enabled, the Open event wouldn't trigger.


----------



## erik.van.geit (Jun 2, 2013)

It was to easy for you to see that 
Any examples of something stupid you did yourself?


----------



## shg (Jun 2, 2013)

I make lots, but I bury them in the back yard.


----------



## shg (Jun 2, 2013)

... and drink to forget.


----------



## the_Intern (Jun 7, 2013)

```
ActiveSheet.PivotTables("PivotTable3").PivotSelect "", xlDataAndLabel, True
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(ISBLANK($C1),AND(ISBLANK($D1),AND(ISBLANK($E1))))"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority    
With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599963377788629
    End With
    Cells.FormatConditions.Delete
```
Was trying to colour subtotal rows for the longest time and couldn't figure out why it wouldn't work... might've recorded a bit too much, long day


----------



## Cindy Ellis (Jun 7, 2013)

Trying to get the maximum within a range, as well as the data from 2 seconds before and after.  About 3AM I gave up, then woke up in the morning realizing why it wasn't returning the maximum, even though Application.Max(Rng) was just fine in debug mode...

```
With Workbooks(df).Worksheets(ds)
 
        For j = 1 To 7
       
            Set Rng = Intersect(.Rows(fdr & ":" & ldr), .Columns(TemperatureCols(j)))
            If Not Rng Is Nothing Then
    
                SummArray((j - 1) * 5 + 9) = .Cells(Application.Match(Application.Max(Rng), Rng, 0) - 2, Rng.Column)
                SummArray((j - 1) * 5 + 10) = .Cells(Application.Match(Application.Max(Rng), Rng, 0) - 1, Rng.Column)
                SummArray((j - 1) * 5 + 11) = .Cells(Application.Match(Application.Max(Rng), Rng, 0), Rng.Column)
                SummArray((j - 1) * 5 + 12) = .Cells(Application.Match(Application.Max(Rng), Rng, 0) + 1, Rng.Column)
                SummArray((j - 1) * 5 + 13) = .Cells(Application.Match(Application.Max(Rng), Rng, 0) + 2, Rng.Column)
       
            End If
       
            Set Rng = Nothing
 
        Next j
 
    End With
```


----------



## ZVI (Jun 15, 2013)

erik.van.geit said:


> ```
> Private Sub Workbook_Open()
> Application.EnableEvents = True
> End Sub
> ```



But curiously this works:

```
Sub Auto_Open()
  Application.EnableEvents = True
End Sub
```
 
And even more curiously - Autpen is not working if workbook is opening via Workbooks.Open


----------

