Take the value of a cell and then use as part of a range in VBA (Excel 2007)

Hatterfan

New Member
Joined
May 29, 2015
Messages
5
Excel 2007. Moderate understanding of VBA code.



Hi all,

I am looking to make a graph that can vary its start date (history) based on a user defined cell.

I have a graph and the coding that will allow it to select the source data range from a defined start point to the end of the data - thus allowing for more data to be added.

Dim lastRow As Long
With Sheets("Debt 90-119 Days")
lastRow = .Range("B" & Rows.Count).End(xlUp).Row

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.SetSourceData Source:=.Range("B1:F" & lastRow)
ActiveChart.Axes(xlCategory).Select
End With

This creates a graph with source data from B1 through to F and down as far as the lowest row with data.

I would like the B1 (as the start point) to be variable and defined upon a different cell (A1).

A1 will consist of a number that matches the row I want the range to start from.

A1 = 5. Data range = B5:F (last row).

Essentially I need the range to be: B(A1):F(last row).

Can anyone help?

Thanks.
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

archstantn

New Member
Joined
Mar 8, 2015
Messages
17
Try the following:
Code:
Dim x As Integer
x = Range("A1").Value
ActiveSheet.Range("B" & x, "F" & lastrow).Select

Then employ the selection to the chart data source with various code
 
Last edited:

Hatterfan

New Member
Joined
May 29, 2015
Messages
5
Perfect.

Slotted into my existing code and works like a dream.

I knew I was on the right lines but couldn't understand how to define x essentially.

Thank you - very much appreciated.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,643
Messages
5,626,052
Members
416,158
Latest member
CaliburBlade138

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
Top