ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   function doubt (https://www.excelbanter.com/excel-programming/413268-function-doubt.html)

xavi garriga

function doubt
 
Dear all;

I'm trying to use a function in my Excel macro and when I call the macro,
appears a message like this:
"Compilation error:
Type of argument of byRef is not coincident." (direct translation from
spanish)

my code is this:

Sub CommandButton1_Click()
Dim filaini, filafi As Integer

For k = 5 To 17
filaini = ActiveSheet.Cells(k, 16).Value
filafi = ActiveSheet.Cells(k + 1, 16).Value
Call calculminim(filaini, filafi)
k = k + 2
Next
End Sub

and the function starts:

Function calculminim(filainicial As Integer, filafinal As Integer)

If you need more part of the code, ask me.

Thank you very much to all!
--
atrep

Niek Otten

function doubt
 
<Dim filaini, filafi As Integer

This defines only filafi as Integer

You need:

Dim filaini as Integer, filafi as Integer

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"xavi garriga" wrote in message ...
| Dear all;
|
| I'm trying to use a function in my Excel macro and when I call the macro,
| appears a message like this:
| "Compilation error:
| Type of argument of byRef is not coincident." (direct translation from
| spanish)
|
| my code is this:
|
| Sub CommandButton1_Click()
| Dim filaini, filafi As Integer
|
| For k = 5 To 17
| filaini = ActiveSheet.Cells(k, 16).Value
| filafi = ActiveSheet.Cells(k + 1, 16).Value
| Call calculminim(filaini, filafi)
| k = k + 2
| Next
| End Sub
|
| and the function starts:
|
| Function calculminim(filainicial As Integer, filafinal As Integer)
|
| If you need more part of the code, ask me.
|
| Thank you very much to all!
| --
| atrep



Rick Rothstein \(MVP - VB\)[_2193_]

function doubt
 
The problem is with this line...

Dim filaini, filafi As Integer

It is not doing what you think. The variable filafi is being declared as an
Integer; however, filaini is being declared as a Variant (your calculminim
function expected it to be an Integer). In VB, all variables must be
declared as to Type individually (this is different from a lot of other
languages. What you need to do is either this....

Dim filaini As Integer, filafi As Integer

or this...

Dim filaini As Integer
Dim filafi As Integer

Rick


"xavi garriga" wrote in message
...
Dear all;

I'm trying to use a function in my Excel macro and when I call the macro,
appears a message like this:
"Compilation error:
Type of argument of byRef is not coincident." (direct translation from
spanish)

my code is this:

Sub CommandButton1_Click()
Dim filaini, filafi As Integer

For k = 5 To 17
filaini = ActiveSheet.Cells(k, 16).Value
filafi = ActiveSheet.Cells(k + 1, 16).Value
Call calculminim(filaini, filafi)
k = k + 2
Next
End Sub

and the function starts:

Function calculminim(filainicial As Integer, filafinal As Integer)

If you need more part of the code, ask me.

Thank you very much to all!
--
atrep



RB Smissaert

function doubt
 
Haven't tested, but try this:

Sub CommandButton1_Click()
Dim filaini As Long
Dim filafi As Long

For k = 5 To 17
filaini = Val(ActiveSheet.Cells(k, 16).Value)
filafi = Val(ActiveSheet.Cells(k + 1, 16).Value)
Call calculminim(filaini, filafi)
k = k + 2
Next
End Sub

Function calculminim(filainicial As Long, filafinal As Long)

The change to Long is not essential, but it has a larger range and is a bit
faster, so there is no point to use Integer here.
Note that the way you had declared filaini it was declared as a variant and
not an Integer as you intended.
Best to put all variable declarations on seperate lines.


RBS


"xavi garriga" wrote in message
...
Dear all;

I'm trying to use a function in my Excel macro and when I call the macro,
appears a message like this:
"Compilation error:
Type of argument of byRef is not coincident." (direct translation from
spanish)

my code is this:

Sub CommandButton1_Click()
Dim filaini, filafi As Integer

For k = 5 To 17
filaini = ActiveSheet.Cells(k, 16).Value
filafi = ActiveSheet.Cells(k + 1, 16).Value
Call calculminim(filaini, filafi)
k = k + 2
Next
End Sub

and the function starts:

Function calculminim(filainicial As Integer, filafinal As Integer)

If you need more part of the code, ask me.

Thank you very much to all!
--
atrep



xavi garriga

function doubt
 
OK, thanks to all. Typical new user mistake :). It happens to me for being
lazy!

--
atrep


"RB Smissaert" wrote:

Haven't tested, but try this:

Sub CommandButton1_Click()
Dim filaini As Long
Dim filafi As Long

For k = 5 To 17
filaini = Val(ActiveSheet.Cells(k, 16).Value)
filafi = Val(ActiveSheet.Cells(k + 1, 16).Value)
Call calculminim(filaini, filafi)
k = k + 2
Next
End Sub

Function calculminim(filainicial As Long, filafinal As Long)

The change to Long is not essential, but it has a larger range and is a bit
faster, so there is no point to use Integer here.
Note that the way you had declared filaini it was declared as a variant and
not an Integer as you intended.
Best to put all variable declarations on seperate lines.


RBS


"xavi garriga" wrote in message
...
Dear all;

I'm trying to use a function in my Excel macro and when I call the macro,
appears a message like this:
"Compilation error:
Type of argument of byRef is not coincident." (direct translation from
spanish)

my code is this:

Sub CommandButton1_Click()
Dim filaini, filafi As Integer

For k = 5 To 17
filaini = ActiveSheet.Cells(k, 16).Value
filafi = ActiveSheet.Cells(k + 1, 16).Value
Call calculminim(filaini, filafi)
k = k + 2
Next
End Sub

and the function starts:

Function calculminim(filainicial As Integer, filafinal As Integer)

If you need more part of the code, ask me.

Thank you very much to all!
--
atrep





All times are GMT +1. The time now is 05:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com