VBA - Array Charts using different Ranges for each sheet? [Code & Workbook Included]

LNG2013

Active Member
Joined
May 23, 2011
Messages
466
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

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
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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