how to view or edit database in pivot table?

learning_grexcel

Active Member
Joined
Jan 29, 2011
Messages
319
I have created a pivot table from a database. Now I wanted to delete and make some changes in the database and it should be automatically affect the pivot table instead of doing it all over again from the source. How it can be done?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

I don't write or understand VBA so I am unable to help you further with code.

If you record a macro whilst you refresh your Pivot Table you should be able to put this in the worksheet code of the sheet where your Database is.

I recorded this macro...

Code:
Sub RefreshPT()
    Sheets("Pivot Table").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub

I then right clicked the worksheet where my Database is, clicked View Code then added this code....

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
RefreshPT
End If
End Sub

I guess this would also work in the Worksheet code....

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Sheets("Pivot Table").Select    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End If
End Sub

You will need to change the sheet name from Pivot Table to the name of the sheet where your Pivot Table is.
You will need to change the Pivot Table name from PivotTable1 to the name of your Pivot Table.

I hope that helps.

Ak
 
Upvote 0
Thanks
I don't know exactly how to do this. I'm completely new to macro....I will be glad if you can explain to me step by step how to use this code in excel 2007
 
Upvote 0
Hi,

Open your workbook.

Press alt F11
Click Insert, click Module
In the white box paste this code...

Code:
Sub RefreshPT()
    Sheets("Pivot Table").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub


This assumes that the sheet with the Pivot Table on is called Pivot Table, if it isn't, change the above to your sheet name. If your Pivot Table is not called PivotTable1 change the above to the name of your Pivot Table.

You could add a button to your worksheet and assign the macro RefreshPT.
When you have made the changes to your database, you can click the button and your Pivot Table will refresh (hopefully) ;)

Good luck.

Ak
 
Upvote 0
Thanks again
I tried but I'm getting the following error :
"runtime error '1004';
Unable to get the PivotTables property of the worksheet class"

I think the problem is Pivottablename. I don't know what is my pivottable name. I just left it "pivottable1" of yours. how to check my pivot table name?
 
Upvote 0
Hi,

I don't understand what you now need to do.

Have you added a button to your database worksheet and assigned the macro to it?

Ak
 
Upvote 0
Thanks Akashwani.......
I don't know which button u r talking about.
I pressed Alt + F11 and I put the code in "insert">> "module" >> saved it. I put my sheet name and pivot table name in the code also.
After that I went to my pivot table to see if I can see anything...but nothing...
 
Upvote 0
Hi,

On your Database worksheet click Insert on the tab at the top.
Click Shapes, select a shape you want to use as a "button".
When you have created the "button", right click it, click Assign Macro.
Double click the macro RefreshPT, save your workbook.

When you make a change to your Database worksheet, click the button and hopefully the Pivot Table will refresh.

Good luck.

Ak
 
Upvote 0
Thanks a lot. It works perfect.

Now I would like to try your second code and third code in post #2 though I don't know what they are meant to.

If I right click my database there is no option called "view code". How to get it?
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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