ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamic range (object variable error) (https://www.excelbanter.com/excel-programming/344353-dynamic-range-object-variable-error.html)

Mslady[_14_]

Dynamic range (object variable error)
 

Hello all,

I need help selecting a range for my chart. The number of rows ar
always going to change. Right now, my code selects A1:E12 and it work
perfectly as long as data is exactly that range, but anything more o
less than that gives errors.

I am trying to select the first and last cell (range for the char
creation), please see code below. but i get "runtime error 91: objec
variable not set". What am i doing wrong? :)


Code
-------------------
Dim end_row As Long
'Set end_row = Sheets("TradeVolume-Chart").Range("A65536").End(xlUp).Row
ActiveSheet.Columns("A:E").Select
end_row = Range("A65536").End(xlUp).Row


Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column on 2 Axes"
ActiveChart.SetSourceData Source:=Sheets("TradeVolume-Chart").Range("A" & end_row), PlotBy:=xlColumns
'ActiveChart.SetSourceData Source:=Sheets("TradeVolume-Chart").Range("A1:E12"), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="TradeVolume-Chart
-------------------

--
Mslad
-----------------------------------------------------------------------
Mslady's Profile: http://www.excelforum.com/member.php...fo&userid=2777
View this thread: http://www.excelforum.com/showthread.php?threadid=48083


Gary Keramidas

Dynamic range (object variable error)
 
try this instead

Range ("A1:E" & end_row)

of Range("A" & end_row)

--


Gary


"Mslady" wrote in
message ...

Hello all,

I need help selecting a range for my chart. The number of rows are
always going to change. Right now, my code selects A1:E12 and it works
perfectly as long as data is exactly that range, but anything more or
less than that gives errors.

I am trying to select the first and last cell (range for the chart
creation), please see code below. but i get "runtime error 91: object
variable not set". What am i doing wrong? :)


Code:
--------------------
Dim end_row As Long
'Set end_row = Sheets("TradeVolume-Chart").Range("A65536").End(xlUp).Row
ActiveSheet.Columns("A:E").Select
end_row = Range("A65536").End(xlUp).Row


Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line -
Column on 2 Axes"
ActiveChart.SetSourceData Source:=Sheets("TradeVolume-Chart").Range("A" &
end_row), PlotBy:=xlColumns
'ActiveChart.SetSourceData
Source:=Sheets("TradeVolume-Chart").Range("A1:E12"), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="TradeVolume-Chart"
--------------------


--
Mslady
------------------------------------------------------------------------
Mslady's Profile:
http://www.excelforum.com/member.php...o&userid=27776
View this thread: http://www.excelforum.com/showthread...hreadid=480837




Mslady[_15_]

Dynamic range (object variable error)
 

please help :) ;)


--
Mslady
------------------------------------------------------------------------
Mslady's Profile: http://www.excelforum.com/member.php...o&userid=27776
View this thread: http://www.excelforum.com/showthread...hreadid=480837


Mslady[_16_]

Dynamic range (object variable error)
 

*sighs....:(


--
Mslady
------------------------------------------------------------------------
Mslady's Profile: http://www.excelforum.com/member.php...o&userid=27776
View this thread: http://www.excelforum.com/showthread...hreadid=480837



All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com