+ Reply to Thread
Results 1 to 11 of 11

How to pass cell references to a sub routine?

  1. #1
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    How to pass cell references to a sub routine?

    Hello folks,

    I have this function:

    Please Login or Register  to view this content.

    Instead of writing the same thing three times I would like to write a sub routine and pass the cell names and go from there.

    How do we pass the cell names ... for example if I want to pass the cell name D7 and then manipulate its value in the sub routine from the cell's name passed in ??

    Thanks

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to pass cell references to a sub routine?

    Perhaps thus
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: How to pass cell references to a sub routine?

    hi xlnitwit ,

    Ok.... although your example works, how does it know to unmerge B6 to B10?????



    ooooopppppssss ok it depends with what area I merged it with... then it unmerges the cells ... ok got it!!1

    Thanks a bunch

    R
    Last edited by RustyNail; 02-16-2018 at 04:15 PM.

  4. #4
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: How to pass cell references to a sub routine?

    Dear xlnitwit !!!

    If we want to merge the range ????

    Below I tried to remerge the same cells but no luck :-(


    I have tried this.... but this gives me error 400 ????


    Please Login or Register  to view this content.
    Thanks for your help

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to pass cell references to a sub routine?

    There is no mergearea if they are not already merged, therefore
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: How to pass cell references to a sub routine?

    Hi xlnitwit,

    Now I have a problem..... It seems like we are working with objects that contain cells packed into a range that we are passing into the functions.
    Which is great stuff.

    But now, in the code sample below, before I merge the cells, I need to clear them. I have done so in the clearCells() function below.

    In the clearCells() function, we are passing the rg range object, and I use the rg.Clearcontents method to clear a series of cells, only this time "horizontally". For example from cells "B6 to D6".

    So for example, from within the clearCells() function, the first function call (see below), will clear the contents of cells B6 to D6, BUT before I do this I need to check if
    cell A6 contains an "X", if it doesn't I go ahead and clear the Contents, if it does contain an "X" then I leave the contents there.

    The next clearCells() function call will clear the contents of cells B7 to D7, BUT before I do this I need to check if
    cell A7 contains an "X", if it doesn't I go ahead and clear the Contents, if it does contain an "X" then I leave the contents there.

    and so .... for the rest of the cells in range...

    The problem I have is, in clearCells() function, before I clear the contents, I somehow need to extract the first cell number and subtract 1 column to the left in order to check if it contains the "X"!!

    And I unfortunately find this a pretty advanced maneuver for me. Should you have a solution, can you please let me know!

    I am so sorry for all the questions, I'm not fluent in VBA, more of a C programmer!
    Thanks so much for your help

    Here's the code:


    Please Login or Register  to view this content.

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to pass cell references to a sub routine?

    The simplest option is to pass the other cell as another argument
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: How to pass cell references to a sub routine?

    thanks so much xlnitwit

    everything works

    r

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to pass cell references to a sub routine?

    You're welcome. Please remember to mark the thread solved.

  10. #10
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274
    Quote Originally Posted by xlnitwit View Post
    You're welcome. Please remember to mark the thread solved.
    Ok can I do this from my phone or do I have to be on my desktop?

    I see no soulevés button on my phone ..... Il check Monday

    Thanks

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to pass cell references to a sub routine?

    Is there a Thread Tools dropdown at the top of the page?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 7
    Last Post: 03-12-2017, 03:20 PM
  2. [SOLVED] Excel 2016 Sort routine issue - recording macro has sheet name in sort routine
    By pongmeister in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-05-2016, 02:45 PM
  3. [SOLVED] naming a routine and calling it in another routine - not a loop
    By HeyInKy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2015, 11:54 AM
  4. Pass a variable from one sub-routine to another sub-routine
    By gowtham_pec in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-01-2013, 07:07 PM
  5. [SOLVED] Pass Variables to Sub Routine in Different Workbook
    By shadyferret in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2013, 09:12 PM
  6. How to pass a worksheet address to a sub routine
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-09-2012, 02:58 PM
  7. Pass Commandbar.Control.caption to sub routine
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-01-2010, 10:51 AM

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