+ Reply to Thread
Results 1 to 7 of 7

I need to send a target.row variable to a User form Initialization sub. Is it Possible?

  1. #1
    Registered User
    Join Date
    05-24-2013
    Location
    Las Vegas
    MS-Off Ver
    Excel 2007
    Posts
    26

    I need to send a target.row variable to a User form Initialization sub. Is it Possible?

    Hello all,

    I thought I would pose another question to the forum as I'm almost out of hair to pull out! I guess when in doubt, turn to those who know more than you do, right? Here is my situation. I have a worksheet that watches a range for changes. When an entry is made in the range, a user form is called. I am pre-populating the user form with information in columns 1-4 of the activeCell.row. However, if the excel installation uses the default "After pressing enter, move selection down" the activeCell.row uses the wrong row number. Since a user form initialization does not take an argument, how can I use the target.row from the sub that called the userform instead of the activecell.row? Is there a way to return the row number of the cell that was most recently changed so that a user form can use it?

    I thank you all for your continued assistance and willingness to assist in furthering my Knowledge.

    Scott
    Last edited by sdavison; 07-26-2013 at 07:33 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,577

    Re: I need to send a target.row variable to a User form Initialization sub. Is it Possibl

    When a change is made, the Change Event gets the address of the cell(s) that have changed, regardless of what the active cell is after Enter is pressed.

    So Target.Row will relate to the cell that has changed. If you want to pass it on, one option is to create a global variable and store the value there. Then you can pick it up in the next routine that needs it.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646
    Scott

    Which worksheet event are you using?
    If posting code please use code tags, see here.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: I need to send a target.row variable to a User form Initialization sub. Is it Possibl

    instead of using userform_initialize (to which you cannot directly pass anything, although you could use a public variable as has been mentioned) you can create your own pubic routine in the form that you can call before showing the form
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    05-24-2013
    Location
    Las Vegas
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: I need to send a target.row variable to a User form Initialization sub. Is it Possibl

    Thank you all for your input and guidance. In this case I am using the worksheet change event which includes a watchrange to find a specific target entry. With each entry a different sub is called and user form if necessary. After exploring options mentioned in responces, It looks like a public variable will accomplish what I am looking for. (It seems simple, but all learning starts off slow). I think I like the idea of a public routine in the form, but I think I have to work towards that as it seems a bit more complex. I like how vba gives one the opportunity to modify the programming method as one continues to learn more. Again, many thanks - I know I couldn't do it without all of you assisting. You have my gratitude.

    Scott

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,577

    Re: I need to send a target.row variable to a User form Initialization sub. Is it Possibl

    @JP:
    you can create your own pubic routine in the form
    Sounds an interesting approach

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: I need to send a target.row variable to a User form Initialization sub. Is it Possibl

    omg! edited now!

+ 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. [SOLVED] Re: Please help for Excel User form send data for multiple worksheets
    By gopala in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 04:08 AM
  2. User form to add attachments and send the form and attachments via outlook
    By scorchio83 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2013, 03:46 AM
  3. VBA: Create User Form That Takes Variable User Inputs
    By sanjeevpandey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2013, 06:14 PM
  4. Using the target command to start user form macro
    By HP RodNuclear in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-07-2011, 02:45 PM
  5. User form and send mail
    By wizard5353 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2005, 11:05 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