+ Reply to Thread
Results 1 to 16 of 16

Linking Partial Cell Data

  1. #1
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Linking Partial Cell Data

    Hello, I am looking for a macro for the following situation:

    I have two cells on Sheet 1 - Cell A1 and Cell A2.

    Cell A1 is the first cell that will receive either a number, or nothing. When it receives a number, the number will always contain five digits. (For example: '23456'.)

    The contents of Cell A2 depend on the contents of Cell A1 - If Cell A1 contains a five digit number, then Cell A2 will display that same five-digit number with '-1' following it. (In our case: '23456-1'.) If Cell A1 contains no number, then Cell A2 will just be another ordinary cell allowing the user to enter whatever he/she desires.

    The extension in Cell A2 should remain editable at all times - if the user wishes to change the '-1' to a '-2', for example, he/she should be able to do so without any error messages appearing. However, the user must not be able to change any of the first five digits in Cell A2 as long as Cell A1 contains data. A message should appear stating that changes to the first five digits should be performed in Cell A1 - which would then change Cell A2 accordingly.

    Also, if the contents of Cell A1 are erased for any reason, Cell A2 should keep the five digit number, but lose whatever '-x' extension it contained.

    Can this be done using Data Validation?
    Last edited by swordswinger710; 01-07-2009 at 12:17 PM.

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Here is one option that should handle what you are trying to accomplish. Right-click on the sheet tab, select View Code, then copy the following code:

    Please Login or Register  to view this content.
    HTH

    Jason

  3. #3
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    A Start

    OK, that's not bad, however, when Cell A1 gets a 5-digit number, I need Cell A2 to display that number plus '-1'. So if Cell A1 gets '12345', then Cell A2 should read '12345-1'.

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Easy enough. Just change:

    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.
    Jason

  5. #5
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Close!

    Okay cool. Now I need to add your code to the one below without any error messages appearing; and the part of the code which checks Cell A1 for 5 digits should be removed in case I want to add a different amount.


    Please Login or Register  to view this content.

    Thanks a million!
    Last edited by swordswinger710; 01-05-2009 at 05:34 PM. Reason: Learned how to post code correctly!

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Ok, try this and let me know how it works:

    Please Login or Register  to view this content.
    Jason

  7. #7
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    A Few Bugs

    Very cool! It's almost there - here's the bugs I found (my actual cell for Cell A1 is Cell B3:E3, and Cell A2 is Cell B8:E8 - they are merged):

    1. When I enter a number into Cell B3:E3 everything goes good until I delete the number, and this error pops up - Run-time error '1004': Cannot change part of a merged cell.

    2. When I have a number entered into Cell B3:E3 and Cell B8:E8 receives that number plus '-1', and I erase the number in Cell B8:E8, I get this error message - Run-time error '13': Type mismatch.

    Here is what should happen -

    1. When the number in Cell B3:E3 gets erased, Cell B8:E8 should lose it's '-x' extension with no messages appearing.

    2. If Cell B3:E3 contains a number and the number in Cell B8:E8 is erased, the same message box we have appearing to prevent the numbers before the '-x' from being changed should appear now.

    Let me know what you think I should do.

  8. #8
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Ok, give this a shot:

    Please Login or Register  to view this content.
    Jason

  9. #9
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    So Close...

    Thanks so much for everything so far . . . there's two more bugs that we need to solve yet.

    1. Occasionally, when changing the number after the dash in Cell B8:E8, I'll get this message: Run-time error '6': Overflow. Not sure why.

    2. If my number in Cell B3:E3 is more or less than five digits, I am unable to change the number after the dash in Cell B8:E8.

    Are these fixable?

  10. #10
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    2. If my number in Cell B3:E3 is more or less than five digits, I am unable to change the number after the dash in Cell B8:E8.
    Well, in your original post, you stated:
    Cell A1 is the first cell that will receive either a number, or nothing. When it receives a number, the number will always contain five digits.
    That is why I wrote the code in that manner. See if this works:
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Apologies

    I'm sorry, I realize I did state the five digit thing, but future speculation brought me to realize that the number of digits could very well change, which is why five digits became irrelevant.

    Your last code fixed the problem with less than five digits, but when I use over five digits and try to change the number after the dash, Error 6 still appears.

    What do you recommend?

  12. #12
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Hmmm. Try changing:

    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Done!

    Awesome! Try as I might, I couldn't get any more error messages. Thanks a million for your help! -Juda

    P.S. I'll be posting another thread shortly, which is quite similar to this one. If you're interested, you could check it out, but only if you want to.

  14. #14
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Good deal. Glad I could help.

    Jason

  15. #15
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Discovered Bug

    Whoops, I found another bug - I can add as many numbers as I want immediately before the dash in Cell B8:E8 without any error messages appearing. The macro should catch this as well if possible. -Juda

  16. #16
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    The Bug Is Dead

    Awesome, the macro at this post fixed the bug:

    http://www.excelforum.com/excel-prog...ml#post2022631

    A thousand thanks for your time, Jason! -Juda

+ 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