View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default passing range to function: type of argument is byref incompatible

How did you declare cTempj (and rngCashOp)? (You didn't share!)

dim cTempj as Range
dim rngCashOp as range

'and I like to be specific
For Each cTempj In rngCAshOP.Cells

mcgurkle wrote:

I'm trying to write some code to traverse a range of cells and, for
each one, to call a function, which returns the address of the nearest
cell above the one passed in, with a lower outline level. In the main
code, I have:

For Each cTempj In rngCAshOP
cTempj.Offset(0, 14).value = fncCellAddCASuperiorItem(cTempj)
Next cTempj

And then:

Function fncCellAddCASuperiorItem(cInferior As Range) As String

Dim cSuperior As Range
Dim i As Integer

i = 0

Do While cSuperior Is Nothing and i < 1000
If cInferior.Offset(-i, 0).EntireRow.OutlineLevel <
cInferior.EntireRow.OutlineLevel Then
cSuperior = cInferior.Offset(-i, 0)
Else
i = i + 1
End If
Loop

fncCellAddCASuperiorItem = cSuperior.Address

End Function

When i run this, i get an error saying the the type of the argument is
byref incompatible. Could anyone please give me some help with where
I'm going wrong?


--

Dave Peterson