+ Reply to Thread
Results 1 to 3 of 3

Creating Gantt chart

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Creating Gantt chart

    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
    UserForm1.Show
    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.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Creating Gantt chart

    How about this?
    replace
    rge = Selection.Address()
    
    with
    rge = Sheets("Schema").Range("A3:D7").Address
    I have no idea how you are display values within that range in your UserForm1
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Creating Gantt chart

    I managed to work it out, the code looks like this:

    Sub Gantt_Chart()
    
    RiSoftGantt.Show
    
    
        'Define the variables.
        Dim ValueAxisMinValue As Date
        Dim Title As String, aChart As Chart
        'Store the location of the data as a string.
        
    
        'Store the start date for the chart.
        ValueAxisMinValue = Sheets("Schema").Range("B3").Value
        'Ask user for the Chart title.
        Title = InputBox("Ange titeln på schemat")
        If Title = vbNullString Then
        Exit Sub
        End If
        '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("Schema").Range("A2:D7"), _
            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 RiSoftGantt.Show is a userform which takes value from the userform and paste it in range "A3:D7"


    Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating a Gantt Chart with data attached...
    By Bayebd24 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-26-2012, 05:33 PM
  2. Creating a Gantt-Like Chart in Excel without using VBA
    By siamadu in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 06-09-2010, 04:05 PM
  3. help me in creating Gantt chart
    By pradeepbm in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 08-07-2009, 06:22 AM
  4. creating gantt chart with bar labels
    By darelooney in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2008, 09:47 AM
  5. Creating A Gantt Chart In Excel
    By SamuelT in forum Excel General
    Replies: 3
    Last Post: 05-23-2006, 09:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1