+ Reply to Thread
Results 1 to 16 of 16

Only the first line of the code is excuted

  1. #1
    Registered User
    Join Date
    05-30-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    68

    Only the first line of the code is excuted

    Hi,
    I have a code for Checkbox to copy cells contents to other cells, it worked perfectly untill I changed the targeted cells due to deliting some rows above the cells and then I got the code copying only one cell centent i.e the first row of the code but not the rest of it, anybody can help to figure out what is wrong, here is the code
    Please Login or Register  to view this content.

    regards
    Emma_B

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Only the first line of the code is excuted

    can you attach a sample file for testing ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Only the first line of the code is excuted

    Hi Emma_B,

    I know this is not solving your issue, but might help you in the future codes to keep your syntax as clean as possible - if you want to use multiple IFs you dont need to do it like you´ve just done (cause for example you rly dont need that else which you have there it does nothing) in this case I´d suggest not if function but case function....you test the check box if its clicked or not so case is 0 or 1....OR if you wanna stick with ifs you can use this kind of syntax:

    Please Login or Register  to view this content.
    in the case scenario it goes like:

    Please Login or Register  to view this content.
    and regarding the solution for your issue, I believe without a sample file we cant reach the conclusion atm - your code seems OK.

    best regards

    Soul

  4. #4
    Registered User
    Join Date
    05-30-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Only the first line of the code is excuted

    here I attach the file.
    Attached Files Attached Files

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,117

    Re: Only the first line of the code is excuted

    those cells are protected.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    05-30-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Only the first line of the code is excuted

    They are not! what do you mean with protected?
    Quote Originally Posted by Andy Pope View Post
    those cells are protected.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,117

    Re: Only the first line of the code is excuted

    yes there are!
    the cells referenced in your code that is not working are protected.

    Please Login or Register  to view this content.
    The ranges referenced in the sample file work, but then they are not protected.

  8. #8
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Only the first line of the code is excuted

    Hm, I dunno where do you have a problem the file you´ve shared is working for me as intended (or described by you) so I see no error

    Soul

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,117

    Re: Only the first line of the code is excuted

    @Soul, the example file references the unlocked cells on the sheet and does indeed work.

    If you then use the new range references from the first post it will fail because those cells are Locked and the sheet is protected.

  10. #10
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Only the first line of the code is excuted

    @Andy....Ofc they will fail, as you said, they are protected. But i thought she is providing use the file with the actual error and therefore I´ve stated there is no error....in the case she provided working file and she wants to implement the ranges mentioned in the first place than she has to, as you have pointed out, unprotect those ranges to make it work....;-)

  11. #11
    Registered User
    Join Date
    05-30-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Only the first line of the code is excuted

    I don't have them as locked cells! forget the first post, in the example file I unprotected the sheet and then selected the whole sheet and went to Format cells >>> Protection and untick the Locked checkbox. but still have the same problem!. when I fill in information in the "Main" part and check the checkbox, only the "Name" i.e range "C21:F21" is copied from the range "C11:F11". this is the problem I have. please do you have any suggestion?

    Quote Originally Posted by Andy Pope View Post
    @Soul, the example file references the unlocked cells on the sheet and does indeed work.

    If you then use the new range references from the first post it will fail because those cells are Locked and the sheet is protected.

  12. #12
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Only the first line of the code is excuted

    @Emma that is not it, the file you´ve provided us, you cant actualy click any cell apart from those where to input data, those are the cells we are talking about...that one you open when you go to "Review" tab and click on unprotect sheet in the "Changes" section

    Soul

    EDIT1: and while protected you cant actualy click the checkbox and therefore the macro wont run, you either need to unprotect that one or dont have it protected at all....I don t know atm if the object resides in a cell so you need to unlock that cell only to make it clickable or if there is some property for that object you need to tweak...but if so I believe there will be someone to tell you that.
    Last edited by SoulPrisoner; 11-21-2013 at 09:47 AM. Reason: Additional info

  13. #13
    Registered User
    Join Date
    05-30-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Only the first line of the code is excuted

    Here I unprotected the sheet and I unlocked all the cells in the sheet and the macro still not working for all the cells it only works to copy the range "C11:F11" to the range "C21:F21" but not any other range, please check the attached file.


    Quote Originally Posted by SoulPrisoner View Post
    @Emma that is not it, the file you´ve provided us, you cant actualy click any cell apart from those where to input data, those are the cells we are talking about...that one you open when you go to "Review" tab and click on unprotect sheet in the "Changes" section

    Soul

    EDIT1: and while protected you cant actualy click the checkbox and therefore the macro wont run, you either need to unprotect that one or dont have it protected at all....I don t know atm if the object resides in a cell so you need to unlock that cell only to make it clickable or if there is some property for that object you need to tweak...but if so I believe there will be someone to tell you that.
    Attached Files Attached Files

  14. #14
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Only the first line of the code is excuted

    Works for me. Have you tried doing it without merged cells (i.e. unmerge them all)

  15. #15
    Registered User
    Join Date
    05-30-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Only the first line of the code is excuted

    This is crazy! I restarted my computer and the code worked perfectly!!
    thank you all for your answers

    E_B

    Quote Originally Posted by yudlugar View Post
    Works for me. Have you tried doing it without merged cells (i.e. unmerge them all)

  16. #16
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Only the first line of the code is excuted

    Happy to hear it´s working now...Excel is sometimes behaving like a naughty kid I can tell you...;-)

    Soul

+ 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: 1
    Last Post: 11-13-2013, 10:28 AM
  2. [SOLVED] Progress indicator not showing when macro is excuted
    By eugh in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-09-2013, 08:20 AM
  3. [SOLVED] SQL Code does not fit in one line in Excel VBA, automatically moves down one line
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2013, 10:56 AM
  4. [SOLVED] Save Data code not saving to the next line, keeps overwriting to same line.
    By Justin25150 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2012, 06:40 AM
  5. Continue line of VBA code on the next line
    By peacelittleone in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-24-2005, 03:05 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