DominicB,
Thanks for your help, but i still cant get this to work.
Here is the full code for the macro.
Sub CreateChart()
Dim strSheetName As String
Dim rngToChart As Range
' get the range to chart
Set rngToChart = Application.InputBox(Prompt:="Select the range you wish to chart.", _
Title:="Select a range.", Type:=8)
rngToChart.Select
' Assign the address of the selected range of cells to a variable.
myRange = Selection.Address
' Assign the name of the active sheet to a variable. This line is
' used in order to allow a chart to be created on a separate chart
' sheet.
mySheetName = ActiveSheet.Name
' Create a name for the new sheet
myGraphSheetName = mySheetName & " Graph"
strSheetName = myGraphSheetName
If IsWorkSheetPresent(strSheetName) Then
' delete the worksheet
On Error Resume Next
Application.DisplayAlerts = False
Sheets(myGraphSheetName).Delete
Application.DisplayAlerts = True
On Error GoTo 0
End If
If IsChartSheetPresent(strSheetName) Then
' delete the chart sheet
On Error Resume Next
Application.DisplayAlerts = False
Charts(myGraphSheetName).Delete
Application.DisplayAlerts = True
On Error GoTo 0
End If
' Add a chart to a seperate sheet
Charts.Add
Application.CutCopyMode = False
' Create the chart
ActiveChart.ChartWizard _
Source:=Sheets(mySheetName).Range(myRange), _
Gallery:=xlLine, Format:=1, PlotBy:=xlColumns, _
CategoryLabels:=1, SeriesLabels:=1, HasLegend:=1, _
Title:=mySheetName, CategoryTitle:="", _
ValueTitle:="", ExtraTitle:=""
' Rename the sheet
ActiveSheet.Name = myGraphSheetName
End Sub
The code stops at the Set rngToChart = Application.Inputbox.......... line
I appreciate your help.
jonnyuk3
Bookmarks