error
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training Sitemap add this page to your favourites/bookmarksBookmark page
 
view a printable version of this pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Error 400

Error 400

resolvedResolved · Medium Priority · Version 2003

replyReplyFri 30 Jul 2010, 11:53Delegate Samantha said...

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

replyReplyMon 2 Aug 2010, 13:30Trainer Stephen said...

RE: Error 400

Hi Samatha

Thanks 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

replyReplyFri 13 Aug 2010, 16:34Delegate Samantha said...

RE: Error 400

Hi

It highlights:

ActiveSheet.Name = strPivot1

replyReplyWed 18 Aug 2010, 15:00Trainer Stephen said...

RE: Error 400

Hi Samantha

Thanks 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.

 

 

Please browse our web site to find out more about
excel training program and other Microsoft training courses.

Excel tip:

Hiding a worksheet in Excel

Want to circulate an Excel workbook file but keep certain worksheets hidden from your colleagues' view?

You can do so by bringing up the sheet you wish to hide on your screen; then going to Format - Sheet - Hide.

It will not be immediately obvious that a sheet is hidden from view unless perhaps the sheet are still labelled Sheet 1, Sheet 2 etc.

To display the sheet again, you can go to Format - Sheet - Unhide on any of the other sheets in the workbook. A dialogue box will appear, allowing you to select the hidden sheet/s. Click OK to make the sheet/s reappear again.

View all Excel hints and tips

forum postHow can i get my logo to appear at the top of every page (in the same postion) almost like a header , so i dont have to keep inserting it myself?

Many Thanks

» Forum post: Company logos


Rate this page:
2.2/5 (213 votes cast)
Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses
Microsoft Certified Partner
Security Seal verified by visa, mastercard securecard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Management training

Professional Skills courses
Project Management Course London
Project Management Courses London
Project Management Training London
Project Management Training
Project Seminar
Project Seminars
Time Management Course London
Time Management London
Time Management Courses London
Time Management Training London
Introduction to Finance course
Assertiveness Skills course
Effective Communications Skills training
Presentation Skills London

Training Formats

Public scheduled courses
On-site training
Closed company courses

Consultancy
Application Development

Blogs

Excel Training
MS Project Training
Microsoft Training Blog

Version differences

Office 2010 vs 2007
MS Project version differences

Training Information

London Computer Training
Computer Training London
Docklands Training Courses
Docklands Training London

Training venues London
Client list
FAQ
Pricing and availability
Course details / Syllabus

Training Articles
Training Information

Microsoft training

Microsoft Office training
& IT Applications

Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training
MS Project courses
MS Project training
Outlook courses
PowerPoint courses
PowerPoint training
VBA courses
Word courses
Microsoft.training
(more...)

Excel Training

Excel courses
Excel Training Courses Medway
Autonumber in Excel
Microsoft Excel training
Basic Excel Courses
Basic Excel Course
Basic Excel Training

Interested in MS Access training?

Access courses
Microsoft Access training
Microsoft access courses
Microsoft training access course
Microsoft+access+training
Access courses in london

Training provider

Training providers
IT training companies
IT training providers
Management Training providers
Management Training provider

Event history, feedback results
Events in 2012 · 2011 · 2010 · More

See also

Crystal Reports training