Y

#### ytayta555

A good day to you all

I forever was searching for maxim speed in my database ;
I never hear before by User Defined Function/Formula , UDF ;
Now , my extreme important goal is to built in column BD ,
Range from row 91 to 65536 my UDF , but I dont know nothing
about VBA Function/ Formula built ! ...

in Range("BD91") , to explain what my worksheet formula do, I show
you this formula :

An perfect equivalent for formula above is the next array formula
which I use actually :

=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0;ISNUMBER(R1:BB45)*{1|1|1|1|1|1|1|
1|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
0|0|0})<=1)
in my locale formula sintax , and in US formula sintax :
=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0,ISNUMBER(R1:BB45)*{1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0})<=1)

in Range("BD92") , all Count functions in formula shall have
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R14;R16) [R16 not
R15 like in BD91!] ;my perfect equivalent array formula
shall look so :
=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0;ISNUMBER(R1:BB45)*{1|1|1|1|1|1|1|
1|1|1|1|1|1|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
0|0|0})<=1)

in Range("BD93") , all Count functions in formula shall have
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R14;R17) [R16 not
R15 like in BD91!] ;my perfect equivalent array formula
shall look so :
=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0;ISNUMBER(R1:BB45)*{1|1|1|1|1|1|1|
1|1|1|1|1|1|1|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
0|0|0})<=1)

in Range("BD121") = When references from Count functions are
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R14;R45) , then in
next cell of range(Range("BD122") references shall look so :
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R15;R16) , so the
moral of this tale is that references are in combinatoric order , 45
numbers taken 15 times

Please very much to help me to built my array formula in VBA , this
UDF is very very important for me . If I have first 2 or 3 examples
for my array formula from BD91 and BD92 ,
I think I'll be able to understand how I must work for the next
others .I want to built in VBA this UDF , but with an array see
to Doug Jenkins comment ) .

[Maybe the array formula above is too complicate ; for an easyer
example , I believe if I have the below easyer example Formulas
write in VBA I'll be able to understand how I must work for the next
more complicate others :
=AND(COUNT(B1;B2;B3)<=1;COUNT(C1;C2;C3)<=1;COUNT(D1;D2;D3)<=1;COUNT(E1;E2;E3)<=1;COUNT(F1;F2;F3)<=1)
=AND(MMULT(TRANSPOSE(ROW(B1:F5))^0;ISNUMBER(B1:F5)*{1|1|1|0|0})<=1)

=AND(COUNT(B1;B2;B3)<=1;COUNT(C1;C2;C4)<=1;COUNT(D1;D2;D4)<=1;COUNT(E1;E2;E4)<=1;COUNT(F1;F2;F4)<=1)
=AND(MMULT(TRANSPOSE(ROW(B1:F5))^0;ISNUMBER(B1:F5)*{1|1|0|1|0})<=1)

=AND(COUNT(B1;B2;B3)<=1;COUNT(C1;C2;C5)<=1;COUNT(D1;D2;D5)<=1;COUNT(E1;E2;E5)<=1;COUNT(F1;F2;F5)<=1)
=AND(MMULT(TRANSPOSE(ROW(B1:F5))^0;ISNUMBER(B1:F5)*{1|1|0|0|
1})<=1) ]
Thank you all so much .

J

#### Joel

Try calling function below with
=CountUDF(R1:BB15)

Function CountUDF(Target As Range)
CountUDF = True
For RowCount = 1 To Target.Rows.Count
MyCount = WorksheetFunction.Count(Target.Rows(RowCount))
If MyCount > 1 Then
CountUDF = False
'Exit Function
End If
Next RowCount
End Function

ytayta555 said:
A good day to you all

I forever was searching for maxim speed in my database ;
I never hear before by User Defined Function/Formula , UDF ;
Now , my extreme important goal is to built in column BD ,
Range from row 91 to 65536 my UDF , but I dont know nothing
about VBA Function/ Formula built ! ...

in Range("BD91") , to explain what my worksheet formula do, I show
you this formula :

An perfect equivalent for formula above is the next array formula
which I use actually :

=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0;ISNUMBER(R1:BB45)*{1|1|1|1|1|1|1|
1|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
0|0|0})<=1)
in my locale formula sintax , and in US formula sintax :
=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0,ISNUMBER(R1:BB45)*{1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0})<=1)

in Range("BD92") , all Count functions in formula shall have
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R14;R16) [R16 not
R15 like in BD91!] ;my perfect equivalent array formula
shall look so :
=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0;ISNUMBER(R1:BB45)*{1|1|1|1|1|1|1|
1|1|1|1|1|1|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
0|0|0})<=1)

in Range("BD93") , all Count functions in formula shall have
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R14;R17) [R16 not
R15 like in BD91!] ;my perfect equivalent array formula
shall look so :
=AND(MMULT(TRANSPOSE(ROW(R1:BB45))^0;ISNUMBER(R1:BB45)*{1|1|1|1|1|1|1|
1|1|1|1|1|1|1|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
0|0|0})<=1)

in Range("BD121") = When references from Count functions are
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R14;R45) , then in
next cell of range(Range("BD122") references shall look so :
COUNT(R1;R2;R3;R4;R5;R6;R7;R8;R9;R10;R11;R12;R13;R15;R16) , so the
moral of this tale is that references are in combinatoric order , 45
numbers taken 15 times

Please very much to help me to built my array formula in VBA , this
UDF is very very important for me . If I have first 2 or 3 examples
for my array formula from BD91 and BD92 ,
I think I'll be able to understand how I must work for the next
others .I want to built in VBA this UDF , but with an array see
to Doug Jenkins comment ) .

[Maybe the array formula above is too complicate ; for an easyer
example , I believe if I have the below easyer example Formulas
write in VBA I'll be able to understand how I must work for the next
more complicate others :
=AND(COUNT(B1;B2;B3)<=1;COUNT(C1;C2;C3)<=1;COUNT(D1;D2;D3)<=1;COUNT(E1;E2;E3)<=1;COUNT(F1;F2;F3)<=1)
=AND(MMULT(TRANSPOSE(ROW(B1:F5))^0;ISNUMBER(B1:F5)*{1|1|1|0|0})<=1)

=AND(COUNT(B1;B2;B3)<=1;COUNT(C1;C2;C4)<=1;COUNT(D1;D2;D4)<=1;COUNT(E1;E2;E4)<=1;COUNT(F1;F2;F4)<=1)
=AND(MMULT(TRANSPOSE(ROW(B1:F5))^0;ISNUMBER(B1:F5)*{1|1|0|1|0})<=1)

=AND(COUNT(B1;B2;B3)<=1;COUNT(C1;C2;C5)<=1;COUNT(D1;D2;D5)<=1;COUNT(E1;E2;E5)<=1;COUNT(F1;F2;F5)<=1)
=AND(MMULT(TRANSPOSE(ROW(B1:F5))^0;ISNUMBER(B1:F5)*{1|1|0|0|
1})<=1) ]
Thank you all so much .

J

#### Joel

Here is another way of doing it without worksheetfunction. I would compare
the two results

Function CountUDF(Target As Range)
CountUDF = True
For RowCount = 1 To Target.Rows.Count
MyCount = 0
ForColcount = 1 to Target.Columns.Count
if IsNumeric(Target.Cells(RowCount,ColCount)) then
MyCount = MyCount + 1
If MyCount > 1 Then
CountUDF = False
'Exit Function
end if
End If
Next ColCount
Next RowCount
End Function

Not sure which on the average will work faster.

Y

#### ytayta555

Please very much to provide me and VBA Functions and for BD93 ,
BD93 , BD121
and BD122 , to understand how I must write the others (from BD91 to
BD65536 )

J

#### Joel

You don't change the function, just change the call

=CountUDF(R1:BB15)

Y

#### ytayta555

You don't change the function, just change the call
=CountUDF(R1:BB15)

I understand that in BD92 I must call =CountUDF(R1:BB14;R16:BB16),
in BD93 =CountUDF(R1:BB14;R17:BB17)
BD121 =CountUDF(R1:BB14;R45:BB45)
BD122 =CountUDF(R1:BB13;R15:BB16)
BD123 =CountUDF(R1:BB13;R15:BB15;R17:BB17)

Am I right ??
But , how I said I want to built them
without use worksheetfunction ;maybe , if it is posible ,
using array ...excuse me I ask more things , but I need them .
Thanks a lot for your time

J

#### Joel

I have found that worksheet functions are usually very effient unless there
is a less complicated method using a UDF. If you have a UDF it is more
efficient to use macro code rather than call a worksheet function when there
ae equivalent methods. It also doesn't use much overhead to call a worksheet
function.

You could use and auxilary column BC and add this formula to row 1 and copy
down the worksheet.
=Count(R1:BB1)<=1

Then at the bottom of the row use Countif to determine if you have any non 1
values
=and(BC1:BC17)

Y

#### ytayta555

I have found that worksheet functions are usually very effient unless there
is a less complicated method using a UDF.  If you have a UDF it is more
efficient to use macro code rather than call a worksheet function when there
ae equivalent methods.  It also doesn't use much overhead to call a worksheet
function.

Indeed , UDF have problem with recalculation , the problem of volatile
formula ,
can occure wrong results ,....; I'll try to see the best method , but
in time ;
maybe you can show me how is to use a macro ...
( If you have a UDF it is more
efficient to use macro code rather than call a worksheet function when there
ae equivalent methods. It also doesn't use much overhead to call a worksheet
function. )
... to understand what is in this ideea .

Thanks so much you initiate me in this new method for me !!

Maybe , another last method and the best is to use , according with
this .....[ Another thing to keep in mind is that a UDF will more
often than
not be less efficient than a deeply nested group of standard
Functions.
This is because Excel's built in Functions are written in the
extremely
fast language, C++. VBA, unfortunately, is a very slow programming
language.]
...according with this , to use C++ for my database .Now , my database
is
in Excel application and VBA programming language , but it isn't

Many thanks again mr. Joel , any ideea and sugestion here is very
apreciated
and usefull for me

J

#### Joel

UDF only have calculation issues if you are referencing worksheet cells
inside a UDF that are not passed as a parameter. the fix is easy by passing
all the worksheet cells through the calling parameters.

ytayta555 said:
I have found that worksheet functions are usually very effient unless there
is a less complicated method using a UDF. If you have a UDF it is more
efficient to use macro code rather than call a worksheet function when there
ae equivalent methods. It also doesn't use much overhead to call a worksheet
function.

Indeed , UDF have problem with recalculation , the problem of volatile
formula ,
can occure wrong results ,....; I'll try to see the best method , but
in time ;
maybe you can show me how is to use a macro ...
( If you have a UDF it is more
efficient to use macro code rather than call a worksheet function when there
ae equivalent methods. It also doesn't use much overhead to call a worksheet
function. )
... to understand what is in this ideea .

Thanks so much you initiate me in this new method for me !!

Maybe , another last method and the best is to use , according with
this .....[ Another thing to keep in mind is that a UDF will more
often than
not be less efficient than a deeply nested group of standard
Functions.
This is because Excel's built in Functions are written in the
extremely
fast language, C++. VBA, unfortunately, is a very slow programming
language.]
...according with this , to use C++ for my database .Now , my database
is
in Excel application and VBA programming language , but it isn't

Many thanks again mr. Joel , any ideea and sugestion here is very
apreciated
and usefull for me

Y

#### ytayta555

HI EVERYBODY AGAIN !

Last days I worked with this UDF .This UDF with worksheetfunction
don't
work : Try calling function below with
=CountUDF(R1:BB15)

Function CountUDF(Target As Range)
CountUDF = True
For RowCount = 1 To Target.Rows.Count
MyCount = WorksheetFunction.Count(Target.Rows(RowCount))
If MyCount > 1 Then
CountUDF = False
'Exit Function
End If
Next RowCount
End Function

It work perfect in the next variant :

Function CountUDF(Target As Range)
Application.Volatile
CountUDF = True
For ColCount = 1 To Target.Columns.Count
MyCount = WorksheetFunction.Count(Target.Columns(ColCount))
If MyCount > 1 Then
CountUDF = False
'Exit Function
End If
Next ColCount
End Function (I changed Row with Column and work perfect)

With my array function , an autofill from BD91 to BD65536 take 65
seconds ;
with this UDF with worksheetfunction inside , take 27 seconds (it's
great!)

The example of UDF without worksheetfunction inside , don't work !
very much everybody to provide me the changes in it to get it work ,
because
work more more fast ( see
http://newtonexcelbach.wordpress.com/2008/05/24/worksheetfunction-vs-...
)

(In a perfect world I'd want so much to be with an array , according
with
the ideas and experiment of here see please
http://www.dailydoseofexcel.com/archives/2007/09/18/performance-monitor/
to Doug Jenkins comment ) .

Please everybody to help me , I'm so nearby to get what I need and
want so much !
Thanks very much to all

J

#### Joel

First, you should put back the "Exit function" to speed up the code. Once
you find one row that is greater than 1 you don't need to test all the other
rows.

Second, it doesn't make sence that the columns work and the Rows don't work.
It must mean that you have two items in one Row but not two items in one
column.

Third, there is an equivalent Count function in VBA to the worksheet
function. It will run a little quicker, but probably not noticable.

Function CountUDF(Target As Range)
CountUDF = True
For RowCount = 1 To Target.Rows.Count
MyCount = Target.Rows(RowCount).Count
If MyCount > 1 Then
CountUDF = False
Exit Function
End If
Next RowCount
End Function

Y

#### ytayta555

First, you should put back the "Exit function" to speed up the code.  Once
you find one row that is greater than 1 you don't need to test all the other
rows.

Thanks so much for quick reply mr. Joel !
It's amasing : now , for an autofill from BD91
to BD65536 take 6 seconds ! It's the dream that I was looking
for !...Here can see
everybody the power of an UDF ...
Second, it doesn't make sence that the columns work and the Rows don't work.
It must mean that you have two items in one Row but not two items in one
column.

Indeed , in one row I can have don't matter how many items , but if in
a column
is more then 1 item , that't what I must find .(My apologise that I
wasn't able to explain
clear , but that's why I posted my worksheet formulas
AND(COUNT(....) , and
AND(MMULT(TR...)) )
Third, there is an equivalent Count function in VBA to the worksheet
function.  It will run a little quicker, but probably not noticable.

Function CountUDF(Target As Range)
CountUDF = True
For RowCount = 1 To Target.Rows.Count
MyCount = Target.Rows(RowCount).Count
If MyCount > 1 Then
CountUDF = False
Exit Function
End If
Next RowCount
End Function

VBA still don't work , but I'm very pleasent for the actual result , 6
seconds
One only problem is now .I have milions of function with references in
combinatoric
order , which , for example, can look so :

=CountUDF(R37:BB37;R39:BB39;R41:BB41;R43:BB43;R45:BB45;R47:BB47;R49:BB49;R51:BB51
;R53:BB53;R55:BB55;R57:BB57;R59:BB59;R61:BB61;R66:BB66;R83:BB83)
with this kind of target UDF function don't work ; it's enough to
have , for example ,
=CountUDF(R37:BB51;R55:BB55) , and it don't work .

Is this an multiple target ? ...is this an array ? ......I don't
know ...
It's last my problem I must fix , the last improvement for speed with
VBA without function inside
doesn't matter so much .
Exist it a way to fix and my last problem ?

[maybe some sugestions for my last problem are here ,
http://www.dailydoseofexcel.com/archives/2007/09/18/performance-monitor/
in the 3-th Doug Jenkins comment ??..]

Y

#### ytayta555

Any kind of sugestion here is more then wellcome for me . Many thanks

J

#### Joel

I think you can use a parameter array. when call the array seperate the
calling variable with a comma instead of a semicomma

Function CountUDF(ParamArray Target() As Variant)
CountUDF = True
MyCount = 0
For MyRow = 0 To UBound(Target())

For RowCount = 1 To Target(MyRow).Rows.Count
MyCount = MyCount + _
WorksheetFunction.Count(Target(1).Rows(RowCount))
If MyCount > 1 Then
CountUDF = False
Exit Function
End If
Next RowCount
Next MyRow
End Function

Y

#### ytayta555

I think you can use a parameter array.  when call the array seperate the
calling variable with a comma instead of a semicomma

IT WORK PERFECT !

5 seconds for an BD91:BD65536 autofill , I dont think
here can be another improvements ;

YOU PROVIDED ME THE DREAM
THAT I WAS LOOKING FOR TO GET IT , no words to thank
you enough for your patience and knowledge share .

Mr. Joel , what can I say ?
Only thing that I wonder is if I shall can sometimes in my life
to can do what you just done for me ! ... Big question for me ;
I'd like to know that for one day the answer will be positive

Y

#### ytayta555

A good day to everybody

I'm so sorry , but I was just hurry , and I haven't check this
UDF function enough ; it is still not working !!...

Is very easy to check : let's work in range B1:G20 ;
we shall use for this example the next macro :
Function CountUDF(ParamArray Target() As Variant)
CountUDF = True
MyCount = 0
For MyRow = 0 To UBound(Target())
For RowCount = 1 To Target(MyRow).Rows.Count
MyCount = MyCount + _
WorksheetFunction.Count(Target(1).Rows(RowCount))
If MyCount > 1 Then
CountUDF = False
Exit Function
End If
Next RowCount
Next MyRow
End Function

in column I row 8 we insert
the UDF =CountUDF(B1:G10;B14:G16;B18:G20) . Without any value in all
cells in
this range (B1:G10) , the UDF return FALSE , what is totaly wrong ,
because this UDF
I need to loop in every column of *ALL* arrays - in all arrays such
as it is one only
column in a only array ;
+++++++++++++++++++++++++++++++++++++++++
in next variant it begin to work , but need some little more
changes :

Function CountUDF(ParamArray Target() As Variant)
CountUDF = True
MyCount = 0
For MyRow = 0 To UBound(Target())
For ColCount = 1 To Target(MyRow).Columns.Count
MyCount = MyCount + _
WorksheetFunction.Count(Target(1).Columns(ColCount))
If MyCount > 1 Then
CountUDF = False
Exit Function
End If
Next ColCount
Next MyRow
End Function

with this line of code :
WorksheetFunction.Count(Target(1).Columns(ColCount)) ,
if we insert in Range("B5:G5") Value = 1 (for example) , the UDF
=CountUDF(B1:G10;B14:G16;B18:G20) will return TRUE , what is right ;
then we
insert in column B14 Value = 5 (for example, doesn't matter if value
is big or small)
, the UDF will return FALSE , what is right ;
BUT , if we delete the content of B14 , and put the value in B19 ,
the UDF will return
TRUE , what is wrong ;
It mean code don't recognise target
2 .....ction.Count(Target(1).Columns(ColCount))

++++++++++++++++++++++++++++++++++++++++
If we have the line of code :
WorksheetFunction.Count(Target(2).Columns(ColCount)),
B14 Value = 5
, the UDF will return TRUE , what is wrong ;
BUT , if we delete the content of B14 , and put the value in B19 ,
the UDF
will return FALSE , what is wright ;
It mean code don't recognise target 1 in this case ;
What I need is the declaration of this targets , to recognise all
targets I need .

If I have 10 targets , it's enough for me ; to recognise something
like :
WorksheetFunction.Count(Target(1;2;3;4;5;6;7;8;9;10).Columns(ColCount))

Thanks very much for your incredible help

Y

#### ytayta555

Please very much to provide me here any kind of ideas , I have
need very strong this UDF to begin built my database .

Y

#### ytayta555

If I may explain myself a little more what
I need to perform this UDF , is to count each
Column separately in a Range of Columns , and in
a Array of Rows . Thank you very much

Y

#### ytayta555

OK, I think I understand what you want better now.
This should work:

IT WORK PERFECT ! IT WORK !

Thank you very much , mr. Doug Jenkins , you're amasing !
Thank you both , and to Joel ; if you believe me or not ,
you made me a MAN , this UDF was my biggest problem .

Now , this UDF for an autofill BD91:BD65536 take
10 seconds , it's a dream .
You could add some code to check the number of
columns in each range, and give a warning if they are not
all the same.

This is not a problem ; this can be maybe a last
improvement : for example 0,3 seconds speed improvement
per workbook for me is very much , it provide me a database
bigger with some few millions functions .
I tried to find the right code for VBA only , to can see the
diference between speed , but without any succes :
Function CountUDF(ParamArray Target() As Variant)
CountUDF = True
range_array = Target(myrange).Value2
For ColCount = 1 To Target(0).Columns.Count
MyCount = 0
For myranges = 0 To UBound(Target())
MyCount = Target(myranges).Columns(ColCount).Count
If MyCount > 1 Then
CountUDF = False
Exit Function
End If
Next myranges
Next ColCount
End Function