Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Error 400
Error 400
Resolved · Medium Priority · Version 2003
Error 400
I'm trying to create a pivot table from a static piece of data and when I've tried to run it get an message box that pops up that says '400'.The code is as follows:
Option Explicit
Dim strActive As String
Dim rngSource As Range
Dim rngDestination As Range
Dim pvtTable As PivotTable
Dim strPivot1 As String
Sub CreateSheet()
Sheets.Add Before:=Sheets(Sheets.Count)
Call DeleteSheet
ActiveSheet.Name = strPivot1
End Sub
Sub PivotActive()
Set rngDestination = Sheets(strPivot1).Range("A1")
Set rngSource = Sheets(strActive).Range("A1").CurrentRegion
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, _
SourceData:=rngSource, tabledestination:=rngDestination, tablename:="TestPivot"
Application.CommandBars("PivotTable").Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
Set pvtTable = Sheets(strPivot1).PivotTables("TestPivot")
With pvtTable
.PivotFields("Consol.Category").Orientation = xlPageField
.PivotFields("Account Description").Orientation = xlRowField
.PivotFields("TC Description").Orientation = xlColumnField
.PivotFields("1011 Budget C").Orientation = xlDataField
.PivotFields("Sum of 1011 Budget C").Function = xlSum
End With
pvtTable.DataBodyRange.Select
Selection.NumberFormat = "[$£]#,##0"
Range("A1").Select
End Sub
Sub DeleteSheet()
Dim wsSheet As Worksheet
Application.DisplayAlerts = False
For Each wsSheet In ActiveWorkbook.Worksheets
If wsSheet.Name = strActive Then
wsSheet.Delete
Exit For
End If
Next wsSheet
Application.DisplayAlerts = True
End Sub
Sub MainPivotRpt1()
Call CreateSheet
Call PivotActive
End Sub
For upcoming training course dates see: Pricing & availability
RE: Error 400
Hi SamathaThanks for your question
When your code crashes, does the VBE open? If so what line of code is highlighted as this will enable me to track down the error more precisely
Thanks
Stephen
RE: Error 400
HiIt highlights:
ActiveSheet.Name = strPivot1
RE: Error 400
Hi SamanthaThanks for your question
Sorry about the delay in responding, and it is possible that you have already found the solution
The code falls over when you try to name the sheet strPivot1. However, your delete sheet procedure deletes a sheet called strActive. So it is likely that you are trying to give the sheet a name that already exists. If you change strActive to strPivot1 you might find that this solves the problem
Regards
Stephen
Wed 25 Aug 2010: Automatically marked as resolved.
|
|
» Forum post: Company logos |



Course updates

