Hello everyone. I currently have a document with dates in column E and corresponding efficiency information in columns BC and BD.
I have made a VB Program which takes an initial date, final date, shift length, and shift # (there are 2 shift #s), and should output a bar graph with from the initial to the final date (x axis) and the efficiency information for that shift and shift #(y axis). The OEE efficiency (which you will see below) is in the 75th column, column BW. The sheet name is Calculation.
Here is my code.
Dim startDate As Date
Dim endDate As Date
If Not Me.OEEOptionButton.Value = "" And Me.ShiftBox.Value = "10 Hour Shift A" Then
With ThisWorkbook.Worksheets("Calculation")
Set startDate = .Columns("E").Find(InitialDate).Row
End With
With ThisWorkbook.Worksheets("Calculation")
Set endDate = .Columns("E").Find(FinalDate).Row
End With
Set DateRange = Range(startDate, endDate)
With ThisWorkbook.Worksheets("Calculation")
startOEE = .Cells(startDate, 75)
endOEE = .Cells(endDate, 75)
End With
Set OEE_Range = Range(startOEE, endOEE)
For Each X In OEE_Range
With ThisWorkbook.Worksheets("Calculation")
checkA = .Columns("F")
check10Hour = .Columns("Z")
If checkA(X) = "A" And check10Hour(X) = True Then
Set Final_OEE_Range = OEE_Range(X)
End If
End With
Next X
Dim cht As ChartObject
Dim xaxis As Range
Dim yaxis As Range
With ActiveChart
'Sets Graph to Bar Graph
.ChartType = x1BarClustered
'Chart name
.SetSourceData Final_OEE_Range
.HasTitle = True
.ChartTitle.Characters.Text = "Overall Equipment Effectiveness 10 Hour Shift A"
'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "OEE (Percent)"
.HasLegend = False
End With
'End If
If Not Me.OperatorEfficiencyOptionButton.Value = "" Then
'Dim xaxis As Range
'Dim yaxis As Range
With ActiveChart
'Sets Graph to Bar Graph
.ChartType = x1BarClustered
'Chart name
.HasTitle = True
.ChartTitle.Characters.Text = "Operator Effiency over Time"
'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Operator Efficiency (Percent)"
.HasLegend = False
End With
End If
Any help with solutions to this code would be great. Currently, I am getting an error "object required" in this line :
Set startDate = .Columns("E").Find(InitialDate).Row
thank you!!
I have made a VB Program which takes an initial date, final date, shift length, and shift # (there are 2 shift #s), and should output a bar graph with from the initial to the final date (x axis) and the efficiency information for that shift and shift #(y axis). The OEE efficiency (which you will see below) is in the 75th column, column BW. The sheet name is Calculation.
Here is my code.
Dim startDate As Date
Dim endDate As Date
If Not Me.OEEOptionButton.Value = "" And Me.ShiftBox.Value = "10 Hour Shift A" Then
With ThisWorkbook.Worksheets("Calculation")
Set startDate = .Columns("E").Find(InitialDate).Row
End With
With ThisWorkbook.Worksheets("Calculation")
Set endDate = .Columns("E").Find(FinalDate).Row
End With
Set DateRange = Range(startDate, endDate)
With ThisWorkbook.Worksheets("Calculation")
startOEE = .Cells(startDate, 75)
endOEE = .Cells(endDate, 75)
End With
Set OEE_Range = Range(startOEE, endOEE)
For Each X In OEE_Range
With ThisWorkbook.Worksheets("Calculation")
checkA = .Columns("F")
check10Hour = .Columns("Z")
If checkA(X) = "A" And check10Hour(X) = True Then
Set Final_OEE_Range = OEE_Range(X)
End If
End With
Next X
Dim cht As ChartObject
Dim xaxis As Range
Dim yaxis As Range
With ActiveChart
'Sets Graph to Bar Graph
.ChartType = x1BarClustered
'Chart name
.SetSourceData Final_OEE_Range
.HasTitle = True
.ChartTitle.Characters.Text = "Overall Equipment Effectiveness 10 Hour Shift A"
'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "OEE (Percent)"
.HasLegend = False
End With
'End If
If Not Me.OperatorEfficiencyOptionButton.Value = "" Then
'Dim xaxis As Range
'Dim yaxis As Range
With ActiveChart
'Sets Graph to Bar Graph
.ChartType = x1BarClustered
'Chart name
.HasTitle = True
.ChartTitle.Characters.Text = "Operator Effiency over Time"
'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Operator Efficiency (Percent)"
.HasLegend = False
End With
End If
Any help with solutions to this code would be great. Currently, I am getting an error "object required" in this line :
Set startDate = .Columns("E").Find(InitialDate).Row
thank you!!
Last edited: