+ Reply to Thread
Results 1 to 6 of 6

Macro problem

  1. #1
    Registered User
    Join Date
    08-31-2005
    Posts
    48

    Macro problem

    Can anyone tell me the problem with this macro, when run an error is thrown and the returnAddress = MyCell.Address is highlighted.

    Function returnAddress(rang As Range, source As String) As Range
    For Each MyCell In rang
    If MyCell = source Then
    returnAddress = MyCell.Address
    End If
    Next MyCell
    End Function


    Thanks,

    Tom

  2. #2
    Norman Jones
    Guest

    Re: Macro problem

    Hi Tomski,

    Try changing:

    > Function returnAddress(rang As Range, source As String) As Range


    to

    Function returnAddress(rang As Range, source As String) As String


    ---
    Regards,
    Norman



    "Tomski" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Can anyone tell me the problem with this macro, when run an error is
    > thrown and the returnAddress = MyCell.Address is highlighted.
    >
    > Function returnAddress(rang As Range, source As String) As Range
    > For Each MyCell In rang
    > If MyCell = source Then
    > returnAddress = MyCell.Address
    > End If
    > Next MyCell
    > End Function
    >
    >
    > Thanks,
    >
    > Tom
    >
    >
    > --
    > Tomski
    > ------------------------------------------------------------------------
    > Tomski's Profile:
    > http://www.excelforum.com/member.php...o&userid=26824
    > View this thread: http://www.excelforum.com/showthread...hreadid=501149
    >




  3. #3
    Registered User
    Join Date
    08-31-2005
    Posts
    48
    Thats works, but the type is important, as I need to use the returned variable in another function that has a Range for an argument.

    If a string is returned then this function doesn't work.

    Is it possible to type cast a string to a range?

    Cheers,

    Tom

  4. #4
    GB
    Guest

    Re: Macro problem

    Instead of just "VARIABLE = New Value" format, you need to use the SET command

    SET VARIABLE = NEW VALUE


    "Tomski" wrote:

    >
    > Thats works, but the type is important, as I need to use the returned
    > variable in another function that has a Range for an argument.
    >
    > If a string is returned then this function doesn't work.
    >
    > Is it possible to type cast a string to a range?
    >
    > Cheers,
    >
    > Tom
    >
    >
    > --
    > Tomski
    > ------------------------------------------------------------------------
    > Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
    > View this thread: http://www.excelforum.com/showthread...hreadid=501149
    >
    >


  5. #5
    Norman Jones
    Guest

    Re: Macro problem

    Hi Tomski,

    Try:

    '=============>>
    Function ReturnCell(rang As Range, SearchString As String) As Range
    Dim MyCell As Range
    For Each MyCell In rang
    If MyCell.Value = SearchString Then
    Set ReturnCell = MyCell
    End If
    Next MyCell
    End Function
    '<<=============

    I changed ReturnAddress to ReturnCell because the former suggests, to me at
    least, a string function. Similarly, I changed Source to SearchString
    because the former suggests a range.

    ---
    Regards,
    Norman



    "Tomski" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Thats works, but the type is important, as I need to use the returned
    > variable in another function that has a Range for an argument.
    >
    > If a string is returned then this function doesn't work.
    >
    > Is it possible to type cast a string to a range?
    >
    > Cheers,
    >
    > Tom
    >
    >
    > --
    > Tomski
    > ------------------------------------------------------------------------
    > Tomski's Profile:
    > http://www.excelforum.com/member.php...o&userid=26824
    > View this thread: http://www.excelforum.com/showthread...hreadid=501149
    >




  6. #6
    Registered User
    Join Date
    08-31-2005
    Posts
    48
    Thanks again, I will give it a try on monday and let you know how it goes.

    Cheers,

    Tom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1