I made a simple macro to be used as a cell function like this:

=MYMACRO(A1;1;"MyString")

So I wrote the function like this:

Function MyMacro(MyInputString As String, MyNumber As Integer, MyString As String) As String
Dim AnotherStringCreatedInThisMacro As String


        'A lot of calculating and stuff down here
        'Blah blah blah
        'Blah blah blah
        'Blah blah blah

        MyMacro=AnotherStringCreatedInThisMacro
End Function


The problem is when A1 (in this case) is empty. It seems like that MyInputString="0" in this case, rather than an empty string.


So I modified my function like this:

Function MyMacro(Cell As Object, MyNumber As Integer, MyString As String) As String
Dim MyInputString As String
Dim AnotherStringCreatedInThisMacro As String


        MyInputString=Cell.getString()

        'A lot of calculating and stuff down here
        'Blah blah blah
        'Blah blah blah
        'Blah blah blah

        MyMacro=AnotherStringCreatedInThisMacro
End Function

When entering =MYMACRO(A1;1;"MyString") into B1, an error message occurs at:
Function MyMacro(Cell As Object, MyNumber As Integer, MyString As String) As String
and it says "BASIC Runtime Error - Object variables blah blah blah" (In Swedish: "BASIC Runtimefel: Objektvariablerna är inte bestämda", which is very strange Swedish and hard to translate to any language...). It's obvious that "Cell As Object" is not the proper way to declare my first parameter.


So how can I get around this?

The only way I can think of right now is this:

Function MyMacro(MyInputString As String, MyNumber As Integer, MyString As String) As String
Dim AnotherStringCreatedInThisMacro As String


        If MyInputString="0" Then
                MyInputString=""
        EndIf

        'A lot of calculating and stuff down here
        'Blah blah blah
        'Blah blah blah
        'Blah blah blah

        MyMacro=AnotherStringCreatedInThisMacro
End Function

This is a very ugly solution, and what about if the cell is SUPPOSED to be "0" rather than just 0.

The problem seems to be that an empty cell is referred to as Cell.Value=0 rather than Cell.String="", so MyInputString "translates" the value of the cell to "0" instead of "".

I hope I didn't complicate things more than necessary.

Any ideas?

--
Johnny

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to