This code executes twice and its not supposed to! I have no idea why its being triggered twice.
Option Explicit
'Double click within pivot table to "select" savings scenario for each row and paste into "Custom Scenario" columns
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim LastRow As Integer
Dim ws As Worksheet
Dim wb As Workbook
Dim i As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False
Set wb = ThisWorkbook
Set ws = wb.Worksheets(1)
LastRow = ws.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Select Case Target.Column 'Basically and If Else, using this value to test criteria
Case 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 'Only do stuff when in these columns
If Not Intersect(Target, Range(Cells(10, Target.Column), Cells(LastRow, Target.Column))) Is Nothing Then 'Only do stuff when in these rows of the column
Select Case Target.Column
Case 7, 9, 11, 13, 15 'Units columns
ws.Cells(Target.Row, 18) = Target.Value 'This column has units
ws.Cells(Target.Row, 19) = Target.Offset(0, 1) 'Next column has savings
ws.Cells(Target.Row, 17) = Cells(8, Target.Column) 'Percent
Case Else 'Savings columns
ws.Cells(Target.Row, 18) = Target.Offset(0, -1) 'Previous column has units
ws.Cells(Target.Row, 19) = Target 'This column has savings
ws.Cells(Target.Row, 17) = Cells(8, Target.Column).Offset(0, -1) 'Previous column has the percent
End Select
End If
End Select
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 8 Then ThisWorkbook.RefreshAll
End Sub
I can step through it one line at a time and see that it is actually going from the End Sub
Statement back to the Pub Sub Worksheet_BeforeDoubleClick
statement. Makes no sense. Thanks in advance!
Edit: I should also mention I am double clicking on a pivot table. Which I know usually brings up a new tab with the data, but Ive used this event before on the same pivot table and its worked no problem. Not sure why this code is different.