The VBA code below charts data on starting at F3 to the last data set on each sheet. My issue is it keeps selecting the same Range on each sheet, basing the range off the first sheet.
Workbook: http://db.tt/Uqxunp8B
Workbook: http://db.tt/Uqxunp8B
Code:
Sub GraphTest7()
Dim lLastRow As Long
Dim vList() As Variant
Dim LastRowGraph1 As Long
Dim ws As Worksheet
'~~~ This is the populated array with the possible sheet names
vList = Array("DataA", "DataB", "DataC", "DataD", "DataE", "DataF", "DataG", "DataH")
Application.ScreenUpdating = False
For j = LBound(vList) To UBound(vList)
On Error Resume Next
Set ws = Sheets(vList(j))
If Err.Number = 0 Then '~~~The code will execute when the sheet exists!
With Sheets(vList(j))
LastRowGraph1 = .Cells(Rows.Count, "F").End(xlUp).Row - 7
lRwA = .Range("A" & Rows.Count).End(xlUp).Row
Charts.Add
With ActiveChart
.ChartType = xlLineMarkers
.SetSourceData Source:=Sheets(vList(j)).Range("F3:F" & LastRowGraph1)
.Location Where:=xlLocationAsObject, Name:=vList(j)
End With
'~~~ This removes the Legend from the chart
With ActiveChart.Legend
.Delete
End With
With Selection.Border
.ColorIndex = 15
.Weight = xlThin
.LineStyle = xlContinuous
End With
'~~~ This adds the gradient colorization for the graph
With ActiveChart.PlotArea
.Fill.TwoColorGradient Style:=msoGradientVertical, Variant:=1
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 37
.Fill.BackColor.SchemeColor = 2
End With
'~~~ This adds the positioningof the graph below the Percentage Tables
With ActiveChart.Parent
.Top = Range("A" & lRwA + 1).Top
.Left = Range("A" & lRwA + 1).Left
End With
End With
End If
Next j
On Error GoTo 0
Application.ScreenUpdating = True
End Sub