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: 41
Default UDF + range object and Offset formula to Value problem

I haven't encountered this one befo

I have just build a UDF which counts cells according to certain criteria
(for other reasons, I want to keep it as a UDF and not put the whole formula
into a cell - which I know how to do.)

Here is the relevant code:
Function DoTheCount(rng as range) as integer

Dim iCol As Integer
Dim aData As Variant

iCol = CInt(rCol.Text)
'rCol is a range object brought in as a parameter. rCol refers to a cell
that itself
'contains a formula =OFFSET(F$91,$R15,0)
' which yields a value, e.g. 37 (which is the column number I want)

Set ws = Worksheets(sht)
'sht is the worksheet I want, e.g. "sheet1"

With ws.Range("A10")
Set rng = Range(.Offset(0, iCol - 1), .Offset(nRows - 1, iCol - 1))
End With

varrayData = rng

'other stuff happens here

DoTheCount = ianswer

End Function
I have two problems:
1. If I try to use rCol.Value (which refers to a cell with an offset
formula), I get '0'
The only way to get the value I want is to use rCol.Text, which will give
me the correct value '37" which I convert to an integer.

2. rng receives the literal values of the range. The first three cells of
the range contain formula (again of the offset(...) kind). Even though they
show a value in the cell, the rng object shows those first three cells as the
literal formula:

'=OFFSET(Std_0!U$5,MATCH($C4,Std_0!$C$6:$C$2912,0) ,0)'

note - the ' ' are added here only to show the result, they are not in
the formula.
the rest of the range has only values in, and these show up correctly in
rng.value or when I dump the whole range into a variant array.

How do I convert the formula in the first three rows of the range to values?
Is there any way I can do it using the straight assignment

varrayData = rng

or do I have to iterate thru the rng cells to extract every value?

Thanks.

 
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
macro problem: range offset question lacy Excel Discussion (Misc queries) 6 September 4th 09 03:31 PM
Offset function problem-Dynamic range MarkM Excel Discussion (Misc queries) 1 November 11th 06 02:41 AM
Problem with Range.Cells.Offset and Range.Cells( row + offset, column) [email protected] Excel Programming 2 August 22nd 05 05:25 AM
Range Object with Find and Offset Ctal[_2_] Excel Programming 1 March 3rd 05 02:45 PM
Dynamic range offset problem! Majeed[_2_] Excel Programming 2 November 8th 04 09:00 PM


All times are GMT +1. The time now is 01:47 PM.

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"