+ Reply to Thread
Results 1 to 25 of 25

Data being cleared in cells when OK pressed on msgbox

  1. #1
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Data being cleared in cells when OK pressed on msgbox

    Hi,

    I have the code below for a msgbox to prompt the user when particular cells have no value, this is within a Macro to copy data to a master sheet. For some reason when I click OK on the msgbox the cells are then emptied.

    Please Login or Register  to view this content.
    Can anyone explain how I can prevent this?

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Data being cleared in cells when OK pressed on msgbox

    Try replacing the above with this

    Please Login or Register  to view this content.
    It may/may not work
    Elegant Simplicity............. Not Always

  3. #3
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Unfortunately not, I get a type mismatch

    This code is within a macro to copy data over to a master sheet, I need the msgbox to run if certain cells have no value & if cells have no value then exit sub at that point & don't copy the data over.

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Data being cleared in cells when OK pressed on msgbox

    I must admit, I'm not too familiar with the syntax used there.. I'm assuming that ws1.Range("FinancialControlsData", "CompetenceData") are two named ranges ??
    If so, you could go to Formulas--> Name manager......... Select the named range and select the formula bar at the bottom - Excel will highlight what the range applies to - there may be a problem with the range itself..

  5. #5
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Yes Andy, they are named ranges. The code I posted first worked fine apart from the fact it was emptying data in all the cells specified when OK was pressed in the msgbox.

    Without the names it would be as follows.....

    Please Login or Register  to view this content.
    I did try with & without named ranges but with no joy

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

    Re: Data being cleared in cells when OK pressed on msgbox

    perhaps
    Please Login or Register  to view this content.
    Josie

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

  7. #7
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Thanks for the response Joseph, this also works the same as my initial code however it is once again emptying the contents of the other cells :/

  8. #8
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Data being cleared in cells when OK pressed on msgbox

    If it's showing you the messagebox and then emptying the ranges anyway there must be some code elsewhere that's doing the damage because the exit sub will take you straight out....

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

    Re: Data being cleared in cells when OK pressed on msgbox

    the code I posted doesn't do anything to any cells-did you leave your
    Please Login or Register  to view this content.
    line in? that's the one clearing the cells

  10. #10
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    No removed all of my code & replaced with yours when tested.

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

    Re: Data being cleared in cells when OK pressed on msgbox

    then you must have some other code running

  12. #12
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    I do, I'm leaving the office now so will post more detail when I get home.

    Thanks for your help so far guys

  13. #13
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Joseph, I've tried this again at home & strangely it appears to be working. How can I get it to highlight the empty cells Yellow?

    Thanks again for your help guys

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

    Re: Data being cleared in cells when OK pressed on msgbox

    perhaps
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Thanks again Joseph, is it possible to remove the highlight once data has been entered?

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

    Re: Data being cleared in cells when OK pressed on msgbox

    sure thing
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    I tried CF but unfortunately it appears to prioritise over VBA

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

    Re: Data being cleared in cells when OK pressed on msgbox

    if you use cf you wouldn't need the vba to do any coloring :-)

  19. #19
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    That doesn't appear to work, the cell stays highlighted yellow once data is entered :/

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

    Re: Data being cleared in cells when OK pressed on msgbox

    the code or the cf?

    a sample workbook could speed this up ;-)

  21. #21
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    The code, I've given up on the CF due to using code like you said.

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

    Re: Data being cleared in cells when OK pressed on msgbox

    what's in the cells-literal values or formulas? the code should work for literal values

  23. #23
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Values, no formulas. If you need a sample then I'll post one later

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

    Re: Data being cleared in cells when OK pressed on msgbox

    yes please

  25. #25
    Forum Contributor
    Join Date
    02-01-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Data being cleared in cells when OK pressed on msgbox

    Hi Joseph,

    It has been a while since I have managed to continue the work on this hence the long delay. I now have some time to carry on. I need to edit your code to check if there is data in a particular column of the table & if there isn't I need it to ignore the empty cells. I have edited it as follows but it doesn't appear to work. Can you help me with this?

    Please Login or Register  to view this content.
    Thanks

+ 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