PC Review


Reply
Thread Tools Rate Thread

Code to Create Chart

 
 
DavidH56
Guest
Posts: n/a
 
      4th Mar 2010
Hi,

I used the macro recorder to create a bar chart. I would like assistance to
simplyfy or make the code more efficient. I've listed the code below.
Thanks in adbance for your assistance:

Sub CreateWIPChart()
Sheets.Add.Name = "List"
Sheets("WIPCON").Select
Columns("H:H").Select
Selection.Copy
Sheets("List").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Columns("A:A").EntireColumn.AutoFit
Sheets("WIPCON").Select
Columns("E:E").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("List").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Columns("B:B").EntireColumn.AutoFit
'Macro3
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"List!R1C1:R938C2").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("SUPV"), "Count of SUPV", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SUPV")
.Orientation = xlRowField
.Position = 1
End With
'Macro7
Range("A5:B5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add.Name = "Chart"
Range("A2").Select
ActiveSheet.Paste
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("E13").Select
Sheets("Chart").Select
Charts.Add
ActiveChart.ChartType = xlBarClustered
ActiveChart.SetSourceData Source:=Sheets("Chart").Range("A2:B31"),
PlotBy _
:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet2"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Supervisors SRV WIPCON"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = False
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold Italic"
.Size = 11
End With
'Macro9
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.37, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 1").ScaleHeight 2.17, msoFalse,
msoScaleFromTopLeft
With ActiveChart.PageSetup
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.ChartSize = xlFullPage
.PrintQuality = 600
.Orientation = xlPortrait
End With
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
Sheets.Add
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "BarChart"
Range("A2").Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Chart 1").Activate
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold Italic"
.Size = 8
End With
ActiveChart.ChartTitle.Select
ActiveChart.PlotArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels AutoText:=True,
LegendKey:= _
False, ShowSeriesName:=False, ShowCategoryName:=False,
ShowValue:=True, _
ShowPercentage:=False, ShowBubbleSize:=False
ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold Italic"
.Size = 9
End With
ActiveChart.SeriesCollection(1).DataLabels.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold Italic"
.Size = 8
End With
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
Range("J15").Select
'Macro10
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 35
.PatternColorIndex = 1
.Pattern = xlSolid
End With
'Macro12
Range("I3").Select
ActiveWindow.DisplayGridlines = False
Range("I10").Select
HideThem
End Sub
Sub HideThem()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
If sh.Name = "Chart" Or sh.Name = "Sheet2" _
Or sh.Name = "List" Then sh.Visible = False
Next sh

End Sub
--
By persisting in your path, though you forfeit the little, you gain the
great.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can/How do you create a chart that can uses VBA code? =?Utf-8?B?c2hlcmlmZg==?= Microsoft Access Reports 2 20th Jul 2007 04:57 PM
Why doesn't the code create a column stacked chart? tskogstrom Microsoft Excel Charting 3 26th Oct 2006 05:27 PM
Create a dynamic chart with code carloshernandezy@gmail.com Microsoft Excel Programming 1 2nd Jul 2005 05:51 PM
Need VBA Code to create/update Pie Chart colors created by a Pivot Table Ali Microsoft Access VBA Modules 0 11th Dec 2003 04:40 PM
VB Code to create or update Pie Chart colors created by a Pivot Table =?Utf-8?B?QWxp?= Microsoft Access VBA Modules 0 9th Dec 2003 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 PM.