+ Reply to Thread
Results 1 to 14 of 14

VBA Code Change Event Code When 2 cells are selected

  1. #1
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    VBA Code Change Event Code When 2 cells are selected

    Looking for a Private Sub Worksheet_Change(ByVal Target As Range) code to concatenate cell J, K, E and F cells when both J6 and K6 are selected. The cells start in J6 and K6. When both J6 and K6 are selected, I would like a VBA code to concatenate J6, K6, E6 and F6 in cell L6 (here is the formula =IF(OR(J6="",K6=""),"",I6&" "&J6 &" "&K6&" - "&E6&" "&" "&F6 I have but looking for a VBA code to accomplish task).

    When either J6 or K6 is selected, the code should not concatenate until both cells (J and K) are selected. I would also like a Clear Contents function to clear L6 (or L7, L100, L80 or L13) contents when either J or K cell is deleted. For example, if K value is deleted, the Clear Contents should clean J and L cells contents.

    Thanks.
    Last edited by bjnockle; 07-15-2014 at 08:52 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA Code Change Event Code When 2 cells are selected

    Hi,

    What you are looking for is actually a Worksheet_SelectionChange event for the concatenation.

    For the cell deletion, you want a Worksheet_Change event.

    Both pieces of code are provided in the attached workbook.

    I hope this helps
    Attached Files Attached Files

  3. #3
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: VBA Code Change Event Code When 2 cells are selected

    Just a lil bit extension of ajryan's ..
    Please Login or Register  to view this content.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  4. #4
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: VBA Code Change Event Code When 2 cells are selected

    ajryan88: The code is not working accurately. Works and stops. The way you have it setup, it does not do beyond J6 and K6. I would like it to end beyond J6 and K6.

    Thanks

  5. #5
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: VBA Code Change Event Code When 2 cells are selected

    Debraj Roy: code is not working. I pasted the code in the sheet1 and it is not working.

    Thanks

  6. #6
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: VBA Code Change Event Code When 2 cells are selected

    Can you please upload a sample file with provided code..

  7. #7
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: VBA Code Change Event Code When 2 cells are selected

    Debraj Roy: file attached. Thanks
    Attached Files Attached Files

  8. #8
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: VBA Code Change Event Code When 2 cells are selected

    Quote Originally Posted by bjnockle View Post
    when both J6 and K6 are selected. The cells start in J6 and K6. When both J6 and K6 are selected, ....
    Do you mean both cell's are populated.. or selected..

    in case of selection.. code is working fine..

  9. #9
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA Code Change Event Code When 2 cells are selected

    My code doesn't extend beyond row 6 because you didn't specify that you wanted it to extend beyond row 6...

    Just change each instance of 6 in the ranges to "Target.Row" and it will work for every row on the worksheet

  10. #10
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: VBA Code Change Event Code When 2 cells are selected

    when both J6 and K6 are populated or values entered, J6 pulls values. Thanks

  11. #11
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: VBA Code Change Event Code When 2 cells are selected

    Quote Originally Posted by bjnockle View Post
    when both J6 and K6 are populated or values entered, J6 pulls values. Thanks
    Please Login or Register  to view this content.
    With your query, the technical term "Worksheet_Change" is only to create confusion...
    Use provided code

  12. #12
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: VBA Code Change Event Code When 2 cells are selected

    VBA.pngDebraj Roy: awesome. It is working as coded. Is it possible to have the formula not show in column L. It notice that values pulled into L is show the formula when you click on the cell. It will be nice to have it display the values only and hide the formula.

    Thanks

  13. #13
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: VBA Code Change Event Code When 2 cells are selected

    Try this one..

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: VBA Code Change Event Code When 2 cells are selected

    Debraj Roy: Works like a charm. thanks for the solution Roy.

+ 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. Fix change event code to add todays date when data is added to multiple cells in column
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 12-21-2013, 06:40 PM
  2. Code to change color and value in calendar cells based on selected dates
    By John74 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2010, 02:01 PM
  3. Change Event - see code in message
    By bforster1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2005, 10:08 AM
  4. Change Event - please check code
    By bforster1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2005, 12:05 AM
  5. Change Event (can someone check this code?)
    By bforster1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2005, 05:14 PM

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