Updating sparklines with VBA

cisco55

New Member
Joined
Mar 8, 2014
Messages
9
Excel 2010

i am attempting to update multiple sparklines with VBA for the first time.
First, I recorded a macro and it returned the following usable code:

Code:
Sub Macro1()
    Range("D9:G9").Select
    ActiveCell.SparklineGroups.Item(1).Modify Location:=Range( _
        "$D$9,$E$9,$F$9,$G$9"), SourceData:= _
        "Data!E2:E8,Data!E9:E15,Data!E16:E22,Data!E23:E29"
    Range("D9,E9,F9,G9").Select
    Range("G9").Activate
End Sub

I have 13 columns (E-Q) in a worksheet called 'Data'. On the active sheet, columns D,E,F,G contain sparkline groups from rows 9-22. Each cell's sparkline is one week worth of data (which is being sorted with a separate macro).

Code:
Sub UpdateSparklines()
Dim h As Integer
Dim i As Integer
Dim j As Integer
Dim Col As Variant
Dim DRange As String
Dim SRange As String
Dim Ar(1 To 13) As Variant


j = 1
For h = 5 To 17
 Ar(j) = Chr(h + 64)
 j = j + 1
Next


i = 9
For Each Col In Ar
 DRange = "$D$" & i & ",$E$" & i & ",$F$" & i & ",$G$" & i
 Range("D" & i & ":G" & i).Select
 SRange = "Data!" & Col & _
        "2:" & Col & "8,Data!" & Col & _
        "9:" & Col & "15,Data!" & Col & _
        "16:" & Col & "22,Data!" & Col & _
        "23:" & Col & "29"
 ActiveCell.SparklineGroups.Item(1).Modify Location:=Range(DRange), SourceData:=SRange
 i = i + 1
Next
End Sub

I couldn't find much out there to help with this, so I thought I would post and ask the question: Do you have suggestions to improve it?

Thank you

Francisco Shillander
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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