Ok, guys i am looking for some help regarding Gant Charts. I have managed to create something similar to what i am working for using an example from Lacher and Gant Charts. i am now stuck as I can enter more than 40 status as it then gives me an error. The following is the code: Can any1 highlight where i need to make any changes to stop the error from occuring:
Option Explicit
Sub CreateTimeChartData()
Dim vTimeData As Variant
Dim i As Integer
Dim sRoom As String
Dim vLastEndTime As Variant
Dim oSeries As Series
'\ set up
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'\ create chart data worksheet
With Worksheets("TimeData").Range("TimeList").CurrentRegion
.Sort Key1:="Room", Key2:="Start Time", Header:=xlYes
vTimeData = .Value
Worksheets.Add
On Error Resume Next
Worksheets("ChartData").Delete
Charts("TimeChart").Delete
On Error GoTo 0
ActiveSheet.Name = "ChartData"
.Columns(1).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("A1"), Unique:=True
End With
Range("a1").Select
For i = 2 To UBound(vTimeData)
If vTimeData(i, 1) <> Selection.EntireRow.Cells(1) Then
Selection.Offset(1).EntireRow.Cells(1).Select
Selection.Value = vTimeData(i, 1)
vLastEndTime = 0
End If
Selection.Offset(0, 1).Select
Selection.Value = vTimeData(i, 2) - vLastEndTime
Selection.Offset(0, 1).Select
Selection.Value = vTimeData(i, 3) - vTimeData(i, 2)
vLastEndTime = vTimeData(i, 3)
Next i
With Selection.CurrentRegion
.Offset(0, 1).NumberFormat = "h:mm AM/PM"
.Columns(2).Cells(1) = "Start Time"
For i = 3 To .Columns.Count
If i Mod 2 <> 0 Then
.Columns(i).Cells(1) = "Used"
Else
.Columns(i).Cells(1) = "Not Used"
End If
Next i
End With
Charts.Add
ActiveChart.Name = "TimeChart"
ActiveChart.ChartWizard Source:=Sheets("ChartData").Range("A1").CurrentRegion, _
Gallery:=xlBar, format:=3, PlotBy:=xlColumns, CategoryLabels _
:=1, SeriesLabels:=1, HasLegend:=2
For Each oSeries In ActiveChart.SeriesCollection
If oSeries.PlotOrder Mod 2 <> 0 Then
oSeries.Border.LineStyle = xlNone
oSeries.Interior.ColorIndex = xlNone
Else
oSeries.Interior.ColorIndex = 5
End If
Next oSeries
With ActiveChart.Axes(xlValue)
.MajorUnit = 0.0416666666
.TickLabels.NumberFormat = "h AM/PM"
.HasMajorGridlines = True
End With
With ActiveChart.Axes(xlCategory)
.ReversePlotOrder = True
End With
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "AGENT STATUS REPORT"
End With
End Sub
Thanks in advance. I have also attached a sample workbook..
Bookmarks