+ Reply to Thread
Results 1 to 42 of 42

Copy Rows If Relative Checkboxes Are Checked - VBA

  1. #1
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi All!

    I'm looking for some VBA code that fulfils the following:

    On Sheet1, each row has a check box in Column A. If a checkbox is checked from Column A, it's corresponding Row copied to Sheet2 when a button is pressed.

    The other Columns on Sheet1 do not have check boxes in them, only certain columns (B, C, F, G, O, P) are to be copied to Sheet2 when the button is pressed.

    When copying to Sheet2, the gaps in-between the Columns should be deleted.

    Thanks in advance,

    Joe

    EDIT: I have tried using code from previous threads, but cant seem to make it work!

  2. #2
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    I have got this piece of code:

    Please Login or Register  to view this content.
    Only trouble is this copies all columns. How would I modify it to only copy the columns B, C, F, G, O & P?

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Quote Originally Posted by Storm08 View Post
    ... On Sheet1, each row has a check box in Column A ...

    ? 1,048,576 check boxes ?

  4. #4
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Quote Originally Posted by porucha vevrku View Post

    ? 1,048,576 check boxes ?
    Maybe not that many.

    There will be up to 300 rows populated.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    I have two pieces of code that will probably, when combined, sort this but please attach a workbook as I have no inclination of re creating....a sample would do with dummy data

  6. #6
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Here's the sample document.

    If you could make it work in this document, that'd be brilliant.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Is this enough information to go on?

  8. #8
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Don't mean to bump this, but I would like to get a solution to this asap.

  9. #9
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Anybody?

  10. #10
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Finally had a chance to look at this.....there is also code to add the checkboxes as they have to be linked to the rows to reference them



    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by nigelog; 02-14-2018 at 11:24 AM.

  11. #11
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Quote Originally Posted by nigelog View Post
    Finally had a chance to look at this.....there is also code to add the checkboxes as they have to be linked to the rows to reference them



    Please Login or Register  to view this content.
    Hi nigelog,

    Thank you very much for helping me out with this. It is working brilliantly!

    I have a question if you dont mind? If I wanted to change the row the range started from, how would this be done? I have realised that I would need to copy from row 3 instead of row 8.

    All the best,
    Joe

  12. #12
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    chane the references to "8" to "3" in the copy section of the code.... thanks for the rep joe

    Please Login or Register  to view this content.
    Last edited by nigelog; 02-20-2018 at 01:23 PM.

  13. #13
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Quote Originally Posted by nigelog View Post
    chane the references to "8" to "3" in the copy section of the code.... thanks for the rep joe

    Please Login or Register  to view this content.
    Ah right! Simple enough! Thank you.

    Also, one last query I have. One of the columns that is copied contains formula. On Sheet1 this is in Column "P", and contains the following: "=F8*O8". When being copied into Sheet2, this moves into Column "G" and should become: "=D8*F8", due to the formula being relative. But what I actually get on Sheet2 in Column "G" is: "#REF!*F8". This suggests that I should be using an absolute formula, but I shouldn't need to due to the cells needing to change when being copied to Sheet2.

    Any ideas?

    P.S - You're welcome for the rep! Well earned!
    Last edited by Storm08; 02-21-2018 at 04:45 AM.

  14. #14
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    I'll have a look

    Please Login or Register  to view this content.
    Last edited by nigelog; 02-21-2018 at 05:23 AM.

  15. #15
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Thanks very much!

  16. #16
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Change this part for new last row value on sheet2
    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    And add a dot to the code:
    Please Login or Register  to view this content.
    And move "If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False" up to "With ... End With", in the form:
    Please Login or Register  to view this content.
    Without it, if you run a macro from a different sheet than 'Sheet1', strange things can happen ...
    From Ms description:
    "Using this property without an object qualifier is equivalent to using ActiveSheet.Rows"
    It also applies to other things ...

  18. #18
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Well spotted perucha, ta

    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Thanks very much. This has corrected the #REF! errors. However, there is more than one formula in the end column. Is there another way to achieve this? Sorry I hadn't explained his before.

    Also, when I un-check a check box on Sheet1, I get the run-time error '1004':We can't do that to a merged cell.

    I have attached an up to date file to demonstrate.
    Attached Files Attached Files

  20. #20
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi
    it is difficult to see all the connections in your sample, please enter representative data in the first two sub heading layouts as you have some formatted for currency yet others are calculated and not formatted. Also rename columns as they would appear as that would help seeing what is going on

    ta

    i cant recreate the merged cell problem, works fine here

  21. #21
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Sorry, I removed too many headings!
    Attached Files Attached Files

  22. #22
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    In the first sheet I would like to see a few rows as they are populated - Unit is carried to second sheet but is involved in no calculations - it could be feet inches or sq miles - be handy to know what was what

    Edit


    As the second sheet is basically a summary report (not an editable document-that should be in the first sheet) then I would suggest no formulas in sheet 2 only values. Some of your calculations involve cells not carried over at all.
    Last edited by nigelog; 02-22-2018 at 05:53 AM.

  23. #23
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Unit is not a cell that is included in any calculation, it just shows what the Qty is of, e.g - hours, days, metres, etc. It can vary.

    The calculation between the columns is Total = Qty x Rate. In the "Total" column, each sub-heading row should calculate the sum of the cells under that sub-heading.

    Also, if a new row is inserted into Sheet1, is it possible for the sheet to automatically add a new checkbox for that row?
    Attached Files Attached Files

  24. #24
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    To enter rows I could only delete and add checkboxes again to keep link

    I had no time to try ans store/retrieve the checkboxes previous value so I checked them all (not a great solution but temporary)

    Update client copies only values now - should not be a working document but a report

    right click for normal excel options and look for "control" - click on it for option menu to appear on sheet1

    hope that helps

    Edit few niggles ironed out
    Attached Files Attached Files
    Last edited by nigelog; 02-22-2018 at 12:41 PM.

  25. #25
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi again,

    This is working almost perfectly now! I have to thank you for coding these functions, and also for your patience with me!

    I have had a thought about the formula in the total column not working. Is it possible to do something along the lines of:

    If row fill colour = rgb(246, 247, 248), calculate the sum of cells below. The range end is when the code gets to another cell with the fill colour of rgb(246, 247, 248). If this is possible and you put this code after the one you came up with previously and use an If Else statement so it doesn't run on blank rows, I think that'd be it.

    Everything else is spot on and is working well. It's just that Sheet2 needs to be able to work on its own.

    EDIT:
    Ah ha! Here's what I was looking for:

    Please Login or Register  to view this content.
    Last edited by Storm08; 02-22-2018 at 01:16 PM.

  26. #26
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    You can do what what you are looking for by setting ranges with "special cells" such as formatting. A few people on here I have seen have a lot of knowledge in this area such as jindon

    Probably best if you start a new thread with just that request "how to sum cells to the next special cell" and utilise that later in the code to select the special cells in sheet 2 and enter a formula....

  27. #27
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Ah right, excellent. Thanks for pointing me in the right direction, I'll start a new thread and reference this one.

    Thank you very much for all of your help, I really appreciate it!

  28. #28
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Sorted

    summing cells on headers will automatically shrink and grow as lines are added deleted

    inserted rows get an linked checkbox

    all data now gets copied to Sheet2


    Last 3 checkboxes on sheet 1 must always be clicked. The headers sum the values by looking for the next cell of the same format - that light shaded line needs to be above the darker shaded one to avoid it including the sheet total
    Attached Files Attached Files
    Last edited by nigelog; 02-23-2018 at 12:14 PM.

  29. #29
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi nigelog,

    Apologies for the delay, I hadn't received an email alert for the thread.

    Thanks very much for the update, I'll have a go and let you know how I get on.
    Last edited by Storm08; 03-13-2018 at 04:53 AM.

  30. #30
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Cant seem to access the "Control Panel" when right clicking. The code for it doesn't seem to be there either?

  31. #31
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi, try this workbook. Must have linked wrong one

    just noticed this leaves data in the clipboard - add the line

    Please Login or Register  to view this content.
    before the end of the copy rows sub
    Attached Files Attached Files
    Last edited by nigelog; 03-13-2018 at 08:19 AM.

  32. #32
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi again,

    This is absolutely spot on! Can't thank you enough for all of your work on this!

    If you don't mind, I have one last function that I have found would need to be added to this sheet. Is that okay?

    Is it possible to recall which checkboxes were selected when adding the checkboxes back?

  33. #33
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi
    I thought of that when I was doing but didn't have time to look at. The checkboxes are linked to a cell on the row and record true or false. That list would have to to be written to either a helper column or an array and replaced to their correct cell, as in taking taking into account what row was added etc. I will take a look at but I think now on this occasion you should start a new thread asking that specific question. It may be answered a lot faster than I could manage.

  34. #34
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Quote Originally Posted by nigelog View Post
    Hi
    I thought of that when I was doing but didn't have time to look at. The checkboxes are linked to a cell on the row and record true or false. That list would have to to be written to either a helper column or an array and replaced to their correct cell, as in taking taking into account what row was added etc. I will take a look at but I think now on this occasion you should start a new thread asking that specific question. It may be answered a lot faster than I could manage.
    Hi,

    No worries at all. The theory behind the recall function makes perfect sense, but I understand how time consuming writing and testing code can be! I'll start a new thread for this item.

    Thanks very much for all of your help, it's greatly appreciated!

    Kind Regards,
    Joe

  35. #35
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    I reckon the best way is to only add a checkbox the row that is highlighted when a row inserted (rather than deleting them all and replacing. I am trying to reference the inserted row but can't quite get the syntax
    this doesn't work
    Please Login or Register  to view this content.


    I suggest trying to adjust the worksheet change sub to not reference the add and delete subs in module 7 but to just add a checkbox to the inserted row
    Please Login or Register  to view this content.
    let me know how you get on
    Last edited by nigelog; 03-14-2018 at 07:44 AM.

  36. #36
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    This will add a checkbox to only the inserted row so all others keep their value (with thanks to Arkadi on here), rather than deleting all and re adding all checkboxes

    Please Login or Register  to view this content.
    if this sorts your request can you mark as solved. Rgds

  37. #37
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hiya,

    Thanks for providing a solution! it works when inserting the check box, but after it's done that, it selects all of the check boxes rather than leaving them in the state they were before.

  38. #38
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Code above definitely does not do that
    Attached Files Attached Files

  39. #39
    Forum Contributor
    Join Date
    01-12-2012
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    104

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    It doesn't in the document you just posted. Must have been me putting it somewhere incorrect.

    However, when I try to click the "Client Update" button, it says "We can't do that to a merged cell".

  40. #40
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    There are no merged cells in that workbook so the error must be in the workbook you have put the code into. Generally merged are nothing but grief - use centre across selection instead - or find another way around using them


    Edit: the merged cells in your original sample workbook are C4:C5 remove the merging and should be ok

    Edit: They are in workbook as well so its not that

    Edit: Code changed to check that checkbox links are correct when rows are entered....
    Attached Files Attached Files
    Last edited by nigelog; 03-15-2018 at 07:01 AM.

  41. #41
    Registered User
    Join Date
    05-08-2018
    Location
    India
    MS-Off Ver
    2010
    Posts
    1

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    pls inbox your excel sheet, i will support you.

  42. #42
    Registered User
    Join Date
    05-08-2018
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    1

    Re: Copy Rows If Relative Checkboxes Are Checked - VBA

    Hi,

    I can help you as well. Is Storm082.xlsm mentioned above, the last version you are working on?

    Best, Konstantin

+ 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. Using checkboxes to copy rows from one sheet to another in the same relative order
    By shammoaero in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2017, 07:02 PM
  2. [SOLVED] Copying Rows Represented By Checked Checkboxes
    By sandy1977 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-02-2017, 10:10 PM
  3. Copy rows if checkboxes are checked
    By KT99 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-01-2014, 03:14 PM
  4. Summing checked checkboxes
    By bermudamohawk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2014, 11:25 AM
  5. Replies: 4
    Last Post: 12-30-2013, 10:10 AM
  6. How to copy only checked checkboxes into new cell?
    By GTX2013 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-06-2013, 09:06 PM
  7. [SOLVED] My checkboxes will not stay checked.
    By NUMBnut in forum Excel General
    Replies: 0
    Last Post: 01-09-2006, 05:10 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