+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 45

Thread: Export Data based cell value

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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 08:37 AM.

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

    Re: Export Data based on tick box

    Please attach the sample workbook.
    Cheers,
    Arlette

    If I 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
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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 10:34 AM.

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

    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?
    Cheers,
    Arlette

    If I 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]

  5. #5
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Export Data based on tick box

    Anyone have answer for this?

  7. #7
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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 Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    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

    Private Sub Checkbox7_Click()
      if checkbox7 then sheets("sheet2").columns(7)=sheets("sheet1").column(7).value
    End Sub



  9. #9
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    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.

    Sub test()
    Dim shpsRng As Collection
    Dim rng As Range
    Dim oCell As Object
    Dim x As Integer
    
    Set shpsRng = New Collection
    
    For x = 1 To Sheet1.Shapes.Count
        If Sheet1.CheckBoxes(x).Value = 1 Then
            shpsRng.Add Sheet1.CheckBoxes(x).TopLeftCell
        End If
    Next x
    
    With Sheet1.Cells(3, 3).CurrentRegion
        For x = 1 To shpsRng.Count
            If shpsRng(x).Row = 1 Then
                If Not rng Is Nothing Then
                   Set rng = Union(rng, .Columns(shpsRng(x).Column - 1))
                Else
                   Set rng = .Columns(shpsRng(x).Column - 1)
                End If
            Else
                If Not rng Is Nothing Then
                    Set rng = Union(rng, .Rows(shpsRng(x).Row - 1))
                Else
                    Set rng = .Columns(shpsRng(x).Row - 1)
                End If
            End If
        Next x
    End With
    
    For Each oCell In rng
       Sheet2.Range(oCell.Address) = oCell.Value
    Next
    
    
    End Sub
    Last edited by Kyle123; 01-16-2012 at 10:04 AM.
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  10. #10
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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 07:24 AM.

  11. #11
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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:

    Sub test()
    Dim shpsRng As Collection
    Dim rng As Range
    Dim oCell As Object
    Dim x As Integer
    
    Set shpsRng = New Collection
    
    For x = 1 To Sheet1.Shapes.Count
        If Sheet1.CheckBoxes(x).Value = 1 Then
            shpsRng.Add Sheet1.CheckBoxes(x).TopLeftCell
        End If
    Next x
    
    With Sheet1.Cells(3, 3).CurrentRegion
        For x = 1 To shpsRng.Count
            If shpsRng(x).Row = 1 Then
                If Not rng Is Nothing Then
                   Set rng = Union(rng, .Columns(shpsRng(x).Column - 1))
                Else
                   Set rng = .Columns(shpsRng(x).Column - 1)
                End If
            Else
                If Not rng Is Nothing Then
                    Set rng = Union(rng, .Rows(shpsRng(x).Row - 1))
                Else
                    Set rng = .Columns(shpsRng(x).Row - 1)
                End If
            End If
        Next x
    End With
    
    For Each oCell In rng
       Sheet2.Range(oCell.Address) = oCell.Value
    Next
    
    
    End Sub
    Otherwise it works brilliantly!

  12. #12
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Export Data based cell value

    What error message do you get?
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  13. #13
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Export Data based cell value

    Try this:
    Sub test()
    Dim shpsRng As Collection
    Dim rng As Range
    Dim oCell As Object
    Dim x As Integer
    
    Set shpsRng = New Collection
    
    For x = 1 To Sheet1.Shapes.Count
        If Sheet1.CheckBoxes(x).Value = 1 Then
            shpsRng.Add Sheet1.CheckBoxes(x).TopLeftCell
        End If
    Next x
    
    If shpsRng.Count <> 0 Then
    
        With Sheet1.Cells(3, 3).CurrentRegion
            For x = 1 To shpsRng.Count
                If shpsRng(x).Row = 1 Then
                    If Not rng Is Nothing Then
                       Set rng = Union(rng, .Columns(shpsRng(x).Column - 1))
                    Else
                       Set rng = .Columns(shpsRng(x).Column - 1)
                    End If
                Else
                    If Not rng Is Nothing Then
                        Set rng = Union(rng, .Rows(shpsRng(x).Row - 1))
                    Else
                        Set rng = .Rows(shpsRng(x).Row - 1)
                    End If
                End If
            Next x
        End With
        
        
        For Each oCell In rng
            Sheet2.Range(oCell.Address) = oCell.Value
        Next
    
    Else
        MsgBox "Nothing was selected"
        
    End If
    
    End Sub
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  14. #14
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    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 11:49 AM.

  15. #15
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Export Data based cell value

    maybe this:

    Sub test()
    Dim shpsRng As Collection
    Dim rng As Range
    Dim oCell As Object
    Dim x As Integer
    
    
    
    Set shpsRng = New Collection
    
    For x = 1 To Sheet1.Shapes.Count
        If Sheet1.CheckBoxes(x).Value = 1 Then
            shpsRng.Add Sheet1.CheckBoxes(x).TopLeftCell
        End If
    Next x
    Sheet2.Range(Sheet1.Cells(3, 3).CurrentRegion.Address).ClearContents
    
    If shpsRng.Count <> 0 Then
        With Sheet1.Cells(3, 3).CurrentRegion
            For x = 1 To shpsRng.Count
                If shpsRng(x).Row = 1 Then
                    If Not rng Is Nothing Then
                       Set rng = Union(rng, .Columns(shpsRng(x).Column - 1))
                    Else
                       Set rng = .Columns(shpsRng(x).Column - 1)
                    End If
                Else
                    If Not rng Is Nothing Then
                        Set rng = Union(rng, .Rows(shpsRng(x).Row - 1))
                    Else
                        Set rng = .Rows(shpsRng(x).Row - 1)
                    End If
                End If
            Next x
        End With
        
        
        For Each oCell In rng
            Sheet2.Range(oCell.Address) = oCell.Value
        Next
    
    Else
        MsgBox "Nothing was selected"
        
    End If
    
    End Sub
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

+ 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.2.0