ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   under (https://www.excelbanter.com/excel-programming/321392-under.html)

Laurent M

under
 
Here is my problem :

I have a GetValue function which returns the value of cell in function of
its abscissa and its ordinate
SetValue sets a value in a cell with the same procedure

-----------------------------------
Function GetValue(S_Fond As String, S_Valeur As String)

Dim Adresse
Adresse = Cells(Range("A:A").Find(S_Valeur).Row,
Range("1:1").Find(S_Fond).Column).Address(False, False)

GetValue = Range(Adresse).value
End Function
-----------------------------------
Function SetValue(S_Fond As String, S_Valeur As String, D_Value)

Dim Adresse As Range
Adresse = Cells(Range("A:A").Find(S_Valeur).Row,
Range("1:1").Find(S_Fond).Column).Address(False, False) *
Range(Adresse).value = D_Value
End Function
-----------------------------------
Then i try to test theses function with a macro

-----------------------------------
Sub GetNumberOfFund()

Dim ad
ad = GetValue("f1c1", "first")

Call SetValue("sec", "InsertData", ad)

End Sub
-----------------------------------

"f1c1" and "sec" are in the first row of my sheet; "first" et "InsertData"
are in the first column

When i execute the macro i get this error (on tje line with an * in SetValue)

I just don't understand where this comes from

Many thanks

Jim Cone

under
 
Laurent,

With range objects, they must be declared..."Dim"
and they must "Set"

They following works for me...
'----------------------------------------
Function SetValue(S_Fond As String, S_Valeur As String, D_Value)
Dim Adresse As Excel.Range

Set Adresse = Cells(Range("A:A").Find(S_Valeur).Row, Range("1:1").Find(S_Fond).Column)
Adresse.Value = D_Value

Set Adresse = Nothing
End Function
'----------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Laurent M" wrote in message
...
Here is my problem :
I have a GetValue function which returns the value of cell in function of
its abscissa and its ordinate
SetValue sets a value in a cell with the same procedure
-----------------------------------
Function GetValue(S_Fond As String, S_Valeur As String)
Dim Adresse
Adresse = Cells(Range("A:A").Find(S_Valeur).Row,
Range("1:1").Find(S_Fond).Column).Address(False, False)
GetValue = Range(Adresse).value
End Function
-----------------------------------
Function SetValue(S_Fond As String, S_Valeur As String, D_Value)
Dim Adresse As Range
Adresse = Cells(Range("A:A").Find(S_Valeur).Row,
Range("1:1").Find(S_Fond).Column).Address(False, False) *
Range(Adresse).value = D_Value
End Function
-----------------------------------
Then i try to test theses function with a macro
-----------------------------------
Sub GetNumberOfFund()
Dim ad
ad = GetValue("f1c1", "first")
Call SetValue("sec", "InsertData", ad)
End Sub
-----------------------------------
"f1c1" and "sec" are in the first row of my sheet; "first" et "InsertData"
are in the first column
When i execute the macro i get this error (on tje line with an * in SetValue)
I just don't understand where this comes from
Many thanks


Bob Phillips[_6_]

under
 
"Jim Cone" wrote in message
...
Laurent,

With range objects, they must be declared..."Dim"


Not so, if not declared as a specific variable type, they will assume
Variant/Empty, and when set to a specific range, will assume Variant/Range.



Laurent M

under
 
I let Adresse be variant and it works

thanks

"Bob Phillips" wrote:

"Jim Cone" wrote in message
...
Laurent,

With range objects, they must be declared..."Dim"


Not so, if not declared as a specific variable type, they will assume
Variant/Empty, and when set to a specific range, will assume Variant/Range.





All times are GMT +1. The time now is 01:35 PM.

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