Function limitations?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I use the property CurrentRegion and then a Range.Rows.Count inside a
function? Inside a Subrutine it works properly but inside a function the
counting gives 0 ... ???!!!

The code is

Function MediaCriticità(Domanda As Integer, Sottodomanda As String) As Double
Dim Nr, Nc As Integer
MacroMedia = 0
Record = 1
Set Destinaz = Worksheets("Calcoli_TMP").Range("A1")
With Sheets("Dati").Cells(1, 1)
Set Zc = .CurrentRegion
Nr = Zc.Rows.Count - 1
Nc = Zc.Columns.Count
Set RecCorr = Zc.Resize(1)
RecCorr.Copy Destinaz
For i = 1 To Nr
Set RecCorr = RecCorr.Offset(1)
If (RecCorr.Cells(4) = Domanda) And (RecCorr.Cells(5) =
Sottodomanda) And (RecCorr.Cells(6) <> 0) Then
Record = Record + 1
If (RecCorr.Cells(7) = 1) Then
MacroMedia = MacroMedia + 1
Set Destinaz = Destinaz.Offset(1)
RecCorr.Copy Destinaz
End If
End If
Next

End With
MacroMedia = MacroMedia / Record
End Function
 
but inside a function the
counting gives 0 ... ???!!!

that would mean no. (function used in a worksheet. function used in VBA
would be no different than a subroutine)
 
If you are calling this function from a formula in a worksheet cell, the .Copy
statements are not legal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top