P
Post Tenebras Lux
I haven't encountered this one before:
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.
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.