Hi Everybody!
I have a code that used to work just fine and now for some reason it stopped working. The code is really helpful and what it does is: you define an specific range of information and the code adds a chart. Now, creates the workbook and the sheet for the chart but the chart itself is not created. Do you know why could this be happening? I am running Microsoft Excel 2007
The code is the following:
I have a code that used to work just fine and now for some reason it stopped working. The code is really helpful and what it does is: you define an specific range of information and the code adds a chart. Now, creates the workbook and the sheet for the chart but the chart itself is not created. Do you know why could this be happening? I am running Microsoft Excel 2007
The code is the following:
Code:
Sub CommandButton1_Click()
Dim oRangeSelected As Range
Dim objExcel As Object
Dim objWorkbook As Workbook
Dim objWorksheet As Worksheet
Dim objRange As Range
Dim objChart As Chart
Dim SeriesCount As Integer
Dim i As Integer
On Error Resume Next
Set oRangeSelected = Application.InputBox( _
Prompt:="Please select a range of cells!",Title:="Select a Range", _
Type:=8)
On Error GoTo 0
If oRangeSelected Is Nothing Then
MsgBox "You are going to cancel this action. Are you Ok?"
Exit Sub
Else
MsgBox "You selected: " & oRangeSelected.Address(External:=True)
End If
Set objExcel = CreateObject
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
oRangeSelected.Copy
objWorksheet.Cells(1, 1).PasteSpecial Paste:=xlPasteValues
Set objRange = objWorksheet.UsedRange
objRange.Select
Set objChart = objExcel.Charts.Add
With objChart
SeriesCount = .SeriesCollection.Count
.Activate
.ChartType = 65
For i = 1 To SeriesCount
.SeriesCollection .Border.Weight = -4138
Next i
.SeriesCollection(1).Border.ColorIndex = 0
.SeriesCollection(1).MarkerBackgroundColorIndex = 0
If SeriesCount > 1 Then
For i = 2 To SeriesCount
.SeriesCollection .Mark
Next i
End If
.HasTitle = True
.ChartTitle.Font.Size = 18
.ChartArea.Fill.Visible = True
.ChartArea.Fill.PresetTextured 15
.ChartArea.Border.LineStyle = 1
.HasLegend = True
.Legend.Shadow = True
'// Switch Row/Columns to rows
.PlotBy = xlRows
End With '// objChart
End Sub