Pivot table + VBA

Closed
shockers Posts 1 Registration date Monday 21 March 2011 Status Member Last seen 21 March 2011 - 21 Mar 2011 à 00:22
RWomanizer Posts 365 Registration date Monday 7 February 2011 Status Contributor Last seen 30 September 2013 - 21 Mar 2011 à 01:09
Hello,

I am very much new to VBA programming in Excel. This is the code.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range
If Target.Address <> "$C$24" Then Exit Sub
Set r = Range("J4")

If Target = 0 Then
With r
.Value = "100"
.Interior.ColorIndex = 4
End With
ElseIf Target > 0 Then
With r
.Value = "100"
.Interior.ColorIndex = 3
End With

End If
End Sub

C24 cell is a Pivot table data. The code works well if it is not Pivot table data.

Name: Pivottable3

Sum of Accidents
Date Total
3/1/2011 0
3/2/2011 0
3/4/2011 0
3/5/2011 0
3/6/2011 0
3/7/2011 0
3/8/2011 0
3/9/2011 2
3/10/2011 2
3/11/2011 2

I need help on how to refer the Total from the pivot table in order to set target address in the code above, to check if it is equal to 0 or > 0

Thanks in advance. I am waiting for your reply.

Prakhash


Related:

1 response

RWomanizer Posts 365 Registration date Monday 7 February 2011 Status Contributor Last seen 30 September 2013 120
21 Mar 2011 à 01:09
there is error in the line

If Target.Address <> "$C$24" Then Exit Sub

use
dim x as long
x = worksheets("worksheet name").range("c24")

If Target.address <> x then exit sub
and then