VBA Form Control to Active X

davidhall

Board Regular
Joined
Mar 6, 2011
Messages
174
I currently have this VBA assigned to a form control button. Can anybody help me write the code to make this an automated active x control.


Sub MyPivot()
'
' MyPivot Macro
'
'
ActiveSheet.PivotTables("PivotTable1").PivotFields("LOAN_NUMBER").CurrentPage = Range("D1").Text
ActiveSheet.PivotTables("PivotTable2").PivotFields("SIFFUL").CurrentPage = Range("D21").Text

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
If that code does what you want, then why change it?

But it's pretty straightforward:

Private Sub CommandButton1_Click
' Your code
End Sub

HTH,
 
Upvote 0
Thanks Smitty.

I am trying to make it so a user doesn't have to click on the button for the pagefield to update.

Cell D1 is linked to another workbook and everything is contingent upon D1. Right now, a user has to click a button for the pagefield to update.
 
Upvote 0
Smitty,

It says Run-time erro '1004

Unable to get the PivotTables property of the Worksheet class

Then I choose the option to debug and it's pointing to the highlighted line below.

Private Sub Worksheet_Calculate()
ActiveSheet.PivotTables("PivotTable1").PivotFields("LOAN_NUMBER").CurrentPage = Range("D1").Text
ActiveSheet.PivotTables("PivotTable2").PivotFields("SIFFUL").CurrentPage = Range("D21").Text

End Sub
 
Upvote 0
Assuming that code is in the module for the sheet containing the pivot tables:
Code:
Private Sub Worksheet_Calculate()
Me.PivotTables("PivotTable1").PivotFields("LOAN_NUMBER").CurrentPage = Range("D1").Text
Me.PivotTables("PivotTable2").PivotFields("SIFFUL").CurrentPage = Range("D21").Text

End Sub
 
Upvote 0
Oops!
Code:
Private Sub Worksheet_Calculate()
On error resume next
Application.EnableEvents = False
Me.PivotTables("PivotTable1").PivotFields("LOAN_NUMBER").CurrentPage = Range("D1").Text
Me.PivotTables("PivotTable2").PivotFields("SIFFUL").CurrentPage = Range("D21").Text
Application.Enableevents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

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