I have the following code:
Sub Gantt_Chart()
UserForm1.Show
'Define the variables.
Dim rge As String
Dim ValueAxisMinValue As Date
Dim shtname As String
Dim Title As String, aChart As Chart
'Store the location of the data as a string.
rge = Selection.Address()
'Store the start date for the chart.
ValueAxisMinValue = Selection.Cells(2, 2).Value
'Ask user for the Chart title.
Title = InputBox("Please enter the title")
'Store the sheet name.
shtname = ActiveSheet.name
'Turn off screen updating.
Application.ScreenUpdating = False
'Create a chart located on a chart sheet.
Set aChart = Charts.Add
With aChart
.ChartWizard Source:=Sheets(shtname).Range(rge), _
Gallery:=xlBar, Format:=3, PlotBy:=xlColumns, _
CategoryLabels:=1, SeriesLabels:=1, HasLegend:=1, _
Title:=Title, CategoryTitle:="", ValueTitle:="", _
ExtraTitle:=""
'Remove the legend.
.Legend.Delete
'Create and format the series.
With .SeriesCollection(1)
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
.InvertIfNegative = False
.Interior.ColorIndex = xlNone
End With
'Modify the category (x) axis.
With .Axes(xlCategory)
.ReversePlotOrder = True
.TickLabelSpacing = 1
.TickMarkSpacing = 1
.AxisBetweenCategories = True
End With
'Modify the value (y) axis.
With .Axes(xlValue)
.MinimumScale = ValueAxisMinValue
.MaximumScaleIsAuto = True
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = False
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
End With
'Turn screen updating back on.
Application.ScreenUpdating = True
End Sub
The
displays values in a range A3:D7 in Sheet"Schema"
In the code above I want to change the range so it is A3:D7. Now it works like this:
You select a range within a sheet
Then you run the macro
Then you enter a title
Then the Chart shows up
I want to skip the part where you select the range manually. Just pick the values thats in Userform1.show
Thank you.
Bookmarks