VBA Bar Graph Code

ameya

Board Regular
Joined
Jun 10, 2014
Messages
105
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!!
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top