Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default range(cells(...))-question

Hi,
I want to address cells dynamically, i.e. have a search function loop
through certain columns. When I write something like
------------------
Function source_range(ByVal sheetname As String, ByVal deliveryperiod
As String) As Range
Dim localloop As Integer
'ThisWorkbook.Worksheets(sheetname).Activate
For localloop = 1 To max_delivery_periods
With ThisWorkbook.Worksheets(sheetname)
If .Cells(delivery_period_row, localloop).Value =
deliveryperiod Then
source_range = .Range(.Cells(1,
localloop), .Cells(max_timeseries_length, localloop)) 'error here!
Exit Function
End If
End With
Next localloop
End Function

('delivery_period_row is a public const of type integer, as well as
max_timeseriws_length)
-----------------------
I get an error, "objectvariable not defined" (or similar). Why is
this, and how can I assign the range "more clever"?

Thanks for any help!
Seb.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default range(cells(...))-question

As far as I can see, delivery_period_row is never loaded, so it will be 0,
so the Cells will be invalid.

--
__________________________________
HTH

Bob

wrote in message
...
Hi,
I want to address cells dynamically, i.e. have a search function loop
through certain columns. When I write something like
------------------
Function source_range(ByVal sheetname As String, ByVal deliveryperiod
As String) As Range
Dim localloop As Integer
'ThisWorkbook.Worksheets(sheetname).Activate
For localloop = 1 To max_delivery_periods
With ThisWorkbook.Worksheets(sheetname)
If .Cells(delivery_period_row, localloop).Value =
deliveryperiod Then
source_range = .Range(.Cells(1,
localloop), .Cells(max_timeseries_length, localloop)) 'error here!
Exit Function
End If
End With
Next localloop
End Function

('delivery_period_row is a public const of type integer, as well as
max_timeseriws_length)
-----------------------
I get an error, "objectvariable not defined" (or similar). Why is
this, and how can I assign the range "more clever"?

Thanks for any help!
Seb.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default range(cells(...))-question

On Jul 28, 10:04 pm, "Bob Phillips" wrote:
As far as I can see, delivery_period_row is never loaded, so it will be 0,
so the Cells will be invalid.

--
__________________________________
HTH

Bob

wrote in message

...

Hi,
I want to address cells dynamically, i.e. have a search function loop
through certain columns. When I write something like
------------------
Function source_range(ByVal sheetname As String, ByVal deliveryperiod
As String) As Range
Dim localloop As Integer
'ThisWorkbook.Worksheets(sheetname).Activate
For localloop = 1 To max_delivery_periods
With ThisWorkbook.Worksheets(sheetname)
If .Cells(delivery_period_row, localloop).Value =
deliveryperiod Then
source_range = .Range(.Cells(1,
localloop), .Cells(max_timeseries_length, localloop)) 'error here!
Exit Function
End If
End With
Next localloop
End Function


('delivery_period_row is a public const of type integer, as well as
max_timeseriws_length)
-----------------------
I get an error, "objectvariable not defined" (or similar). Why is
this, and how can I assign the range "more clever"?


Thanks for any help!
Seb.


Hi Bob,

sorry, I forgot to mention: delivery_period_row as well as
max_delivery_periods are public constants, and they are loaded
(integers with values nicely loaded).

Any other suggestion?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default range(cells(...))-question

Function source_range(ByVal sheetname As String, ByVal deliveryperiod As
String) As Range
Dim localloop As Long

'ThisWorkbook.Worksheets(sheetname).Activate
For localloop = 1 To max_delivery_periods

With ThisWorkbook.Worksheets(sheetname)

If .Cells(delivery_period_row, localloop).Value = deliveryperiod
Then

Set source_range = .Range(.Cells(1, localloop),
..Cells(max_timeseries_length, localloop)) 'error here!
Exit Function
End If
End With
Next localloop
End Function


--
__________________________________
HTH

Bob

wrote in message
...
On Jul 28, 10:04 pm, "Bob Phillips" wrote:
As far as I can see, delivery_period_row is never loaded, so it will be
0,
so the Cells will be invalid.

--
__________________________________
HTH

Bob

wrote in message

...

Hi,
I want to address cells dynamically, i.e. have a search function loop
through certain columns. When I write something like
------------------
Function source_range(ByVal sheetname As String, ByVal deliveryperiod
As String) As Range
Dim localloop As Integer
'ThisWorkbook.Worksheets(sheetname).Activate
For localloop = 1 To max_delivery_periods
With ThisWorkbook.Worksheets(sheetname)
If .Cells(delivery_period_row, localloop).Value =
deliveryperiod Then
source_range = .Range(.Cells(1,
localloop), .Cells(max_timeseries_length, localloop)) 'error here!
Exit Function
End If
End With
Next localloop
End Function


('delivery_period_row is a public const of type integer, as well as
max_timeseriws_length)
-----------------------
I get an error, "objectvariable not defined" (or similar). Why is
this, and how can I assign the range "more clever"?


Thanks for any help!
Seb.


Hi Bob,

sorry, I forgot to mention: delivery_period_row as well as
max_delivery_periods are public constants, and they are loaded
(integers with values nicely loaded).

Any other suggestion?



Reply
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
Question about a range of cells Cerberus Excel Discussion (Misc queries) 2 April 1st 08 06:29 PM
Range.(Cells()) question [email protected] Excel Programming 3 March 21st 06 04:30 AM
how to compute a range of cells based on another range of cells? HAROLD Excel Worksheet Functions 2 December 30th 05 07:55 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


All times are GMT +1. The time now is 08:28 PM.

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

About Us

"It's about Microsoft Excel"