Adding ranges to selected range

charging rhinos

New Member
Joined
Jun 23, 2011
Messages
4
Hello to all. I have been assigned a vba project that requires me to make some rather complicated graphs. I'll try my best to explain:

The row portion of the sheet I use for my data has 39 entries. These end up being the legend items in a stacked column graph. The issue i have to fix is that the graphs must be monstrous in size to fit all 39 of those legend items, and most of them are empty and not being used in the graph. I would like to select only the items that have data in that row, and create the graph from a selection of those lines alone. This is the code, with comments, that I have thus far. I am attempting to 1) find the rows with data in them, then 2) select the portion of the row that will be used for the graph, and 3) find the next row with data and add it to that first selection, repeating until all rows have been checked.


Code:
Dim CurrentRange As Range
Dim MultiRange As Range

For i = 1 To 39     'Find all rows with issue marks at any point and add them to the selected range

    Range("M" & i + 3).Select 'this is the totals column where i determine if the row has data in it
    If ActiveCell.Value > 0 Then
    Range("A" & i + 3, "L" & i + 3).Select 'this selects the data needed for the chart to display properly
    Set CurrentRange = Range("A" & i + 3, "L" & i + 3) 'save the selection as a range

    Set MultiRange = MultiRange + CurrentRange 'add the currently selected range to the main range to be used in the graph
    End If
Next i
I know that the MultiRange range variable is not defined in this block of code, which I could do if needed. It just seems like there must be a FAR getter way to do this. I've tried it with the Union function, and it gives me trouble, since the vast majority of the 39 rows if items are empty and cause Union to fail.

Thanks very much in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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