+ Reply to Thread
Results 1 to 5 of 5

Passing a range to a function

  1. #1
    David Bell
    Guest

    Passing a range to a function

    Formul in Excel looks like this:
    =TestForEach(F7:J8)

    Function TestForEach(a As Range)
    Dim cell As Range
    For Each cell In Range(a)
    Msgbox("Hello")
    Next
    End Function

    Whats worg with this picture. I am trying to pass a range of cells from
    excel to this function and nothing happens. For some reason I am not using
    the "a" range correctly.

  2. #2
    Nick Hodge
    Guest

    Re: Passing a range to a function

    David

    Not sure what your function does but a is already set to a range so just use
    a

    Function TestForEach(a As Range)
    Dim cell As Range
    For Each cell In a
    Msgbox("Hello")
    Next
    End Function


    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    www.nickhodge.co.uk
    [email protected]HIS


    "David Bell" <David [email protected]> wrote in message
    news:[email protected]...
    > Formul in Excel looks like this:
    > =TestForEach(F7:J8)
    >
    > Function TestForEach(a As Range)
    > Dim cell As Range
    > For Each cell In Range(a)
    > Msgbox("Hello")
    > Next
    > End Function
    >
    > Whats worg with this picture. I am trying to pass a range of cells from
    > excel to this function and nothing happens. For some reason I am not using
    > the "a" range correctly.




  3. #3
    Nick Hodge
    Guest

    Re: Passing a range to a function

    slight correct...know what it's doing...don't know why ;-)

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    www.nickhodge.co.uk
    [email protected]HIS


    "Nick Hodge" <[email protected]> wrote in message
    news:[email protected]...
    > David
    >
    > Not sure what your function does but a is already set to a range so just
    > use a
    >
    > Function TestForEach(a As Range)
    > Dim cell As Range
    > For Each cell In a
    > Msgbox("Hello")
    > Next
    > End Function
    >
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > www.nickhodge.co.uk
    > [email protected]HIS
    >
    >
    > "David Bell" <David [email protected]> wrote in message
    > news:[email protected]...
    >> Formul in Excel looks like this:
    >> =TestForEach(F7:J8)
    >>
    >> Function TestForEach(a As Range)
    >> Dim cell As Range
    >> For Each cell In Range(a)
    >> Msgbox("Hello")
    >> Next
    >> End Function
    >>
    >> Whats worg with this picture. I am trying to pass a range of cells from
    >> excel to this function and nothing happens. For some reason I am not
    >> using
    >> the "a" range correctly.

    >
    >




  4. #4
    David Bell
    Guest

    Re: Passing a range to a function

    I need to check a range of cells for materials choosin for a beam,
    ie. DF, DF #2 & Btr, DF #1, PSL, LVL, ect

    They may select 1 or several materials to use for the beam check.
    The user needs to send me a range where the materials are specified and then
    I will do calculations to determine the min size and material for the beam
    and / or give them a choice of all amterials and sizes allowable

    Formula in Excel looks like this:
    =TestForEach(F7:J8)

    Function TestForEach(a As Range)
    Dim cell As Range
    For Each cell In Range(a)
    'Msgbox("Hello")
    Call CalculatMinimumBeamSize(cell, returnvalue)
    Next
    End Function


  5. #5
    David Bell
    Guest

    Re: Passing a range to a function

    I got it working, Thanks for the help. The problem was the "in a" instead of
    "Range(a)" and using "cell" for the data

+ 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