LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How do I programmatically build a range?

I have a fixed range of cells (41) that I need to chart. The user may or may
not fill all the final cells. I need to exclude these unused cells at the end
from the chart.

Dim LastColReservedCell As Integer
Dim LastActiveCell As Integer
Dim MyRange As Range

LastActiveCell = 0
LastColReservedCell = 41

For Each c In Worksheets("Charts").Range _
("B1:B41").Cells

If c.Value < 1 Then
Blanks = Blanks + 1
Else
Blanks = Blanks
End If
Next

LastActiveCell = LastColReservedCell - Blanks

'Here is where the problem starts. Trying to build the range generates an
error 13.
MyRange = "A1:" + LastActiveCell

'If I can build a valid Range, I would like to use it as shown below:

ActiveChart.SetSourceData Source:=Sheets("Charts").Range(MyRange), PlotBy _
:=xlColumns

'Using (MyRange) instead of ("A1:B41")

Is this possible?

Thank You for your help.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Build Select Case Programmatically Dave Birley Excel Programming 11 June 1st 07 05:39 PM
Build a range from a cell [email protected] Excel Programming 3 April 12th 07 11:08 PM
How to build a forward/back range finder John Wirt[_10_] Excel Programming 1 July 24th 05 09:21 PM
How do I programmatically specify a range. Hari[_3_] Excel Programming 4 January 17th 05 03:31 PM
How to build build a macro that automatically imports PedroPeso Excel Programming 1 December 26th 03 08:14 PM


All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"