+ Reply to Thread
Results 1 to 9 of 9

Passing cell value to sub routine perform action on relative cells

  1. #1
    Registered User
    Join Date
    06-09-2010
    Location
    ireland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Passing cell value to sub routine perform action on relative cells

    Hi there,

    I'm fairly a novice at excel vba but im trying to understand how to perform the following.

    I would like to run a sub routine that would perform an action on the relative cells for the cell that is passed to the sub, such as:

    Please Login or Register  to view this content.
    Apologies for the basic errors here, but would anyone have any advice as to how to perform such action or a recommendation for a good tutorial covering this.

    Any help or advice greatly appreciated.

    Cheers

    Noel

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Passing cell value to sub routine perform action on relative cells

    You're pretty much there though you would use a Range variable

    Please Login or Register  to view this content.
    You would in turn invoke the above passing the appropriate range reference

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Passing cell value to sub routine perform action on relative cells

    Maybe something like:

    Please Login or Register  to view this content.

    You would then use it on your worksheet like =TimesTwo(A1) and it will return the value in A1 multiplied by 2.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Passing cell value to sub routine perform action on relative cells

    Please Login or Register  to view this content.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Passing cell value to sub routine perform action on relative cells

    snb, not very practical nor very straightforward for a beginner.

    Why the use of Split over a basic Array ?

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Passing cell value to sub routine perform action on relative cells

    @DonkeyOte
    Did I comment on your suggestions ? My suggestions are meant for the TS, not for you. Let the TS decide what to use.
    Passing variables to functions or subs isn't for beginners.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Passing cell value to sub routine perform action on relative cells

    You didn't answer my question as to why you used Split ?

    I was curious to know if there was some solid reasoning behind it.

    Regards passing variables - I based my response on the title of the thread.

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Passing cell value to sub routine perform action on relative cells

    Quote Originally Posted by snb View Post
    @DonkeyOte
    Did I comment on your suggestions ? My suggestions are meant for the TS, not for you. Let the TS decide what to use.
    Passing variables to functions or subs isn't for beginners.
    I'd like to think everyone would be glad to learn if there's a better way to do things. Nobody ever taught me programming so it's only by looking at other people's suggestions that I'm picking it up. If folk can't ask you for an explanation it's not much point making a suggestion.

    Just my opinion.

    Dom

  9. #9
    Registered User
    Join Date
    06-09-2010
    Location
    ireland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Passing cell value to sub routine perform action on relative cells

    Thanks everybody greatly appreciate all the advice, and alternative methods, great way of learning as Dom said. There is nothing wrong with a little discussion either

    Really big help, cheers

    Noel

+ 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