Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Worksheet_change or Worksheet_calculate

Hi,

I have code to change the field values in all pivot tables on Sheet1
based on the values entered in some specific cells. On cell A2 I have
a formula and I need the code to be triggered when it recalculates so
it will change the pivot table field value. The problem is that the
code I have works perfectly when the value is manually entered but not
when it changes based on a formula. Also tried the
Worksheet_Calculate () event but I don't know how to prevent the
"Object Required" error.

Would greatly appreciate the help!!

Code is pasted below:

Private Sub Worksheet_change(ByVal target As Range)
Dim a(10, 2) As Integer
Dim fieldadd(10, 2) As String
fieldadd(1, 1) = "$A$2"
fieldadd(1, 2) = "Name"
Application.ScreenUpdating = False
If (target.Address) = fieldadd(1, 1) Then
For Each pt In ActiveSheet.PivotTables
For Each pt1 In ActiveSheet.PivotTables
pt1.PivotFields(fieldadd(1, 2)). _
CurrentPage = target.Value
Next pt1
On Error Resume Next
Next pt
End If
target.Select
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default Worksheet_change or Worksheet_calculate

Hi

The Worksheet_calculate event does not have a Target object, which is what
your existing code requires.

HTH. Best wishes Harald


"karaeloko" wrote in message
...
Hi,

I have code to change the field values in all pivot tables on Sheet1
based on the values entered in some specific cells. On cell A2 I have
a formula and I need the code to be triggered when it recalculates so
it will change the pivot table field value. The problem is that the
code I have works perfectly when the value is manually entered but not
when it changes based on a formula. Also tried the
Worksheet_Calculate () event but I don't know how to prevent the
"Object Required" error.

Would greatly appreciate the help!!

Code is pasted below:

Private Sub Worksheet_change(ByVal target As Range)
Dim a(10, 2) As Integer
Dim fieldadd(10, 2) As String
fieldadd(1, 1) = "$A$2"
fieldadd(1, 2) = "Name"
Application.ScreenUpdating = False
If (target.Address) = fieldadd(1, 1) Then
For Each pt In ActiveSheet.PivotTables
For Each pt1 In ActiveSheet.PivotTables
pt1.PivotFields(fieldadd(1, 2)). _
CurrentPage = target.Value
Next pt1
On Error Resume Next
Next pt
End If
target.Select
Application.ScreenUpdating = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Worksheet_change or Worksheet_calculate

Hello Harald,

Yes you are right. The problem is that I don't know how to fix it and
that is the reason why I posted it here to see if someone might help.

I found the code I'm using on the internet and as I mentioned it works
perfectly when the values are manually entered in the cell but not if
there is a formula that changes based on another cell.

regards,
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Worksheet_change or Worksheet_calculate

On Aug 6, 7:33*pm, karaeloko wrote:
Hello Harald,

Yes you are right. The problem is that I don't know how to fix it and
that is the reason why I posted it here to see if someone might help.

I found the code I'm using on the internet and as I mentioned it works
perfectly when the values are manually entered in the cell but not if
there is a formula that changes based on another cell.

regards,


Modify to suit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
Select Case Target.Address
Case Is = Range("a1").Address, Range("c3").Address
MsgBox "Hi"
Case Else
End Select
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet_Change vs Worksheet_Calculate Beans Excel Programming 2 August 5th 09 10:01 PM
Re : Excel Worksheet_Calculate() & Worksheet_Change() [email protected] Excel Programming 0 March 3rd 08 09:31 AM
Worksheet_Calculate or Worksheet_Change? Aria Weston Excel Programming 6 February 6th 07 11:29 PM
Nesting worksheet_Calculate inside worksheet_CHANGE Justin Luyt Excel Programming 5 September 1st 06 02:40 AM


All times are GMT +1. The time now is 10:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"