Horesz89
03-27-2023, 06:36 AM
Dear All,
I am a newbie at VBA and I would like to create a function (not a Sub) to be used at any range and for any given value in the workbook. The Function should be used for replacing characters in the values. So far I have tried 2 codings:
1st:
Function Chatrim(incorref As Double) As Double
Chatrim = replace(incorref, "2022/", "") incorref is the chosen value and the expected result would be like : incorref = 2022/445 expected result with the function is 445
End Function
2nd:
Function Replacechar(incorvalue As Double) As Double
Range(incorvalue).replace What:="2022/", Replacement:=""
'incorvalue is the chosen value and the expected result would be like : incorvalue = 2022/445 expected result with the function is 445
End Function
For both above functions I get the result: #VALUE!
Thank you for your help!
I am a newbie at VBA and I would like to create a function (not a Sub) to be used at any range and for any given value in the workbook. The Function should be used for replacing characters in the values. So far I have tried 2 codings:
1st:
Function Chatrim(incorref As Double) As Double
Chatrim = replace(incorref, "2022/", "") incorref is the chosen value and the expected result would be like : incorref = 2022/445 expected result with the function is 445
End Function
2nd:
Function Replacechar(incorvalue As Double) As Double
Range(incorvalue).replace What:="2022/", Replacement:=""
'incorvalue is the chosen value and the expected result would be like : incorvalue = 2022/445 expected result with the function is 445
End Function
For both above functions I get the result: #VALUE!
Thank you for your help!