Automating a Pivot Table

  • Thread starter Thread starter Droidy
  • Start date Start date
D

Droidy

I have a spreadsheet that I import different amounts of data to each
day, overwriting the previous days each time.
I want to automate the production of a Pivot Table based on the data in
the spreadsheet.
I know I can use the PivotTableWizard which refers to a named range
"Database" if it exists.

I have the following code:-

Public Sub SetNameRange()

Worksheets("Data").Activate
ActiveSheet.UsedRange.Select

Sheets("Data").Names.Add Name:="Database",
RefersTo:=ActiveSheet.UsedRange.Select

End Sub

This selects the used range but will not add the name to the
spreadsheet. Does anyone have any idea where i am going wrong?
 
You could change the code to:

Public Sub SetNameRange()
ActiveWorkbook.Names.Add Name:="Database", _
RefersTo:=Worksheets("Data").UsedRange
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top