+ Reply to Thread
Results 1 to 45 of 45

Export Data based cell value

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

    Export Data based cell value

    Hi all!

    First post on here so hello My query is quite straightforward, I need to export data from one spreadsheet into another, new spreadsheet (which should be created when the macro is run). The idea is that each column and row will have a tick box at the top/side of them, the user will tick each column or row that the want on the other spreadsheet and when a button is clicked, the whole lot gets copied to the newly created sheet (without the links).

    Is this do able? I have tried to make it work but im not very fluent in vba at all.

    Attachment 136043

    Thanks in advance

    Storm08
    Last edited by Storm08; 01-24-2012 at 09:37 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Export Data based on tick box

    Please attach the sample workbook.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

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

    Re: Export Data based on tick box

    I cant put the actually sheet on here because of confidential reasons but here's an example to give you an idea
    I dont know what the best way would be to go about it, it's had me stumped for a good few days because of my limited experience with programming in vb.
    Thanks for the reply
    Attached Files Attached Files
    Last edited by Storm08; 01-12-2012 at 11:34 AM.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Export Data based on tick box

    So if a checkbox is clicked, which sections should be copied? For example, in your attachment, if only A3 is clicked, then should only row 3 be copied without the headers?

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

    Re: Export Data based on tick box

    Basically if the checkbox on a row is checked then get the macro to select it, if a column is selected as well then add the whole row to the selection, then what ever has been select will get copied when a button is clicked. Sorry if im asking a lot, i was just wondering what would be the best way to go about it was and how.

    Thank you

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

    Re: Export Data based on tick box

    Anyone have answer for this?

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

    Re: Export Data based on tick box

    Would it be possible to do this based on a cells contents. For instance, there are columns with headings at the top, above each heading there is a box that will either say T or F (True of False).
    When the macro is run, each column that says "T" will be copied to a new document with all of the values that the column holds. Is this possible or not?

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export Data based cell value

    assuming:
    - the data in sheet1
    - the sheet to be copied to sheet2
    - the ActiveX-checkbox for column G Checkbox7

    Please Login or Register  to view this content.



  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    I don't really get what you are after, but give this a go.

    It will put it onto sheet 2 in the first instance, but can be easily adapted to another workbook.

    Please Login or Register  to view this content.
    Last edited by Kyle123; 01-16-2012 at 11:04 AM.

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

    Re: Export Data based cell value

    Wow, thanks for the replies, ill give them a go and let you know
    Last edited by Storm08; 01-17-2012 at 08:24 AM.

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

    Re: Export Data based cell value

    UPADTE! It seems to be working very well apart from when i un-check a box, it breaks at the red code:

    Please Login or Register  to view this content.
    Otherwise it works brilliantly!

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    What error message do you get?

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Try this:
    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    The error message doesnt come up anymore and the message box appears when you uncheck it. Would it be possible to undo or delete the column of data when the box is unchecked?

    Sorry im asking a lot, i would like to try and do it myself but im still trying to get my head round your first bit of code :P

    This is a massive help so far! thank you very much!

    EDIT:

    Oh and also,it only copies a certain amount to the other sheet. I would have changed the range of data copied but i wasn't sure what to change.
    Last edited by Storm08; 01-17-2012 at 12:49 PM.

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    maybe this:

    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    That did work very well, but now it comes up with this error: 'The index into the specified collection is out of bounds'

    It's on this line: If Sheet1.CheckBoxes(x).Value = 1 Then

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

    Re: Export Data based cell value

    **"Accidental duplicate post"**

  18. #18
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Are you moving adapting this cod efor another workbook. The only way you could get that error is if there are no checkboxes on the worksheet

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

    Re: Export Data based cell value

    Nope, i have moved check boxes around though. there are 400+ checkboxes, should that be a problem?

  20. #20
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Try changing this:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    And see if it works

  21. #21
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export Data based cell value

    or
    Please Login or Register  to view this content.

  22. #22
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    or that ^^

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

    Re: Export Data based cell value

    haha, Ill give it a go! also do the check boxes just need to be in a row or a column or do they have to be referenced to a cell? just so i can take out the true/false if i dont need it.

    Cheers! +REP

  24. #24
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Well the reference for which rows/columns to copy is based on which cell the checkbox is in.

    So really they need to be in the top row and first column

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

    Re: Export Data based cell value

    Okay, that makes sense now the code snb came up with works when copying but not when deleting them off of Sheet2. how would i go about putting that? I know the basic format of the code but not in this circumstance.

  26. #26
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Like this:

    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    Quote Originally Posted by Kyle123 View Post
    Like this:

    Please Login or Register  to view this content.
    No joy with that piece of code :o

  28. #28
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export Data based cell value

    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    That's what im looking for!!! ..lets see if it worrks....

    YUP!!! works a treat, thanks very much, if i have any other queries then ill let you know thank you very much! :D

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

    Re: Export Data based cell value

    if i tick a column and then untick a row, it still shows the data in that row if the columns are ticked, should just show a blank row.

    EDIT: It takes quite a while to copy or delete now, is there a way to limit the cell range it copys/deletes? thank you!

    EDIT EDIT: Would it be able to copy links as well as cell data so when it is change it changes on the other sheet as well?
    Last edited by Storm08; 01-18-2012 at 12:05 PM.

  31. #31
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export Data based cell value

    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    Sorry about the delay, this looks like it might just work, although atm i have an error - "Object Required", that comes up here:

    Please Login or Register  to view this content.

  33. #33
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export Data based cell value

    It means you have to analyse the code, and to debug it.

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

    Re: Export Data based cell value

    thats what i've tried to do, except i dont realy have an experience with vb :/

    EDIT: Tried editing the code but had no luck
    Last edited by Storm08; 01-19-2012 at 08:07 AM.

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

    Re: Export Data based cell value

    Dont mean to be hassle but it would be nice to get this working sometime tomorrow.

    Thanks,
    Storm08

  36. #36
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Stick the code in the sheet1 code rather than a module and try it - or fully qualify the UsedRange
    Last edited by Kyle123; 01-19-2012 at 12:57 PM.

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

    Re: Export Data based cell value

    Quote Originally Posted by Kyle123 View Post
    Stick the code in the sheet1 code rather than a module and try it - or fully qualify the UsedRange
    I tried putting in into the sheet code but i dont think it liked it :p when you say qualifying the used range dyou mean this?: http://www.homeandlearn.co.uk/excel2...l2007s7p6.html

    And what would i select for the range? just one column?

  38. #38
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    No, I mean like this:
    Please Login or Register  to view this content.
    Becomes
    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    Ah okay, i get you know Sorry, trying to learn programming properly because the only stuff i have done is at college. and that's next to nothing :/

  40. #40
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    You have to be explicit when using code in modules, you need to tell it which sheet to reference as it has no idea. When using it in the sheet object, in this example it will use the sheet that the columns are in by default.

    Whilst learning it is probably a good idea to always be explicit as it makes it easier for you to understand exactly what's going on, also in general step through the code and have the locals window open when you are learning, you get a much better insight of what is going on.

    You can also query particular bit of code in the immediate window for example:

    Please Login or Register  to view this content.

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

    Re: Export Data based cell value

    I try to be explicit but dont always know what im doing :P i find it helps to do it all the time unless it may cause an error. Thanks very much for the info, better than all of the college tutors! :P

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

    Re: Export Data based cell value

    EDIT: Good news, i got rows and columns working successfully interestingly, it only works up to a certain amount of rows. goes up to 283 and then doesn't copy anything. the data on the sheet finishes at row 326, so it takes out a fair chunk.

    Any ideas?

    Thanks,
    Storm08

    EDIT: Okay... dont worry, i just found a slightly strange solution... o.0

    All i did was put a thick border along the left hand side of the spreadsheet and it worked...

    how did that make a difference???
    Last edited by Storm08; 01-20-2012 at 10:26 AM.

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

    Re: Export Data based cell value

    Hey guys, The code is work very well now, just 1 problem, when the data is copied to the second sheet, the data copies fine but underneath the data, all the cells have " #N/A " in them. there's about 16000 rows of it each time. :/

    I dont know what to do, would be happy for any help

    Thank you,
    Storm08

  44. #44
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Export Data based cell value

    Do you have any formulas in the rows below?

    I would say (without having seen your workbook) that the first issue was caused by having a blank row in your data

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

    Re: Export Data based cell value

    That first issue is sorted now, i dont really know what it was but its gone :P and i dont have any formula in the rows below, it's completely empty.

    EDIT:Managed to sort it
    Last edited by Storm08; 01-24-2012 at 09:36 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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