Function test(a As Integer, b As Integer)
Evaluate "test1(" & Application.Caller.Offset(0, 1).Address(0, 0) & "," & a & "," & b & ")"
test = ""
End Function
Sub test1(c As Range, a As Integer, b As Integer)
c = a + b
End Sub作者: Andy2483 時間: 2023-5-24 08:21
Option Explicit
Function MyCustomFunction(ByVal arg1 As String, ByVal arg2 As String) As String Evaluate "test1(工作表1!A1,""" & arg1 & """,""" & arg2 & """)"
MyCustomFunction = ""
End Function
Function test1(c As Range, a As String, b As String)
c = a & b
End Function作者: dou10801 時間: 2023-5-25 15:10
Function MyCustomFunction(arg1, arg2, V%) '自訂函數只給結果值, 不能指定存放位置
Dim result
If V = 1 Then result = Val(arg1) + Val(arg2)
If V = 2 Then result = arg1 & arg2
MyCustomFunction = result
End Function
Sub TEST() '給自訂函數[參數],再指定填入位置, 須按鈕執行
Sheets("工作表2").[B2] = MyCustomFunction(100, 200, 1)
Sheets("工作表2").[B3] = MyCustomFunction("我的自訂", "函數", 2)
End Sub作者: Andy2483 時間: 2023-5-26 07:34
Option Explicit
Function MyCustomFunction(arg1, arg2, V%) '自訂函數只給結果值, 不能指定存放位置
'↑自訂函數MyCustomFunction(),(arg1,arg2)宣告為通用型變數,V是短整數
Dim result
'↑宣告變數:result是通用型變數
If V = 1 Then result = Val(arg1) + Val(arg2)
'↑如果V變數是 1,就令result變數是 兩變數各轉為數值後相加值
If V = 2 Then result = arg1 & arg2
'↑如果V變數是 2,就令result變數是 兩變數相連接後的新字串
MyCustomFunction = result
'↑令MyCustomFunction函數回傳 result變數值
End Function