+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Transferring data from cells to another sheet if criteria is met

  1. #1
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Transferring data from cells to another sheet if criteria is met

    Hey guys, this is my first post and I really hope someone will be able to help me. So here is a little background on my project. I am an environmental engineer doing different risk/health assessments on various sites. My excel (2007) file has 4 sheets. The first three are based on increasing health and safety risks uncovered at the sites (i.e green, amber and red).

    Each sheet (1,2 and 3) contains 3 columns. A contains abbreviations for a certain risk, B has a description of that risk, and C is for a yes/no checklist if the health and safety risk described in that row applies to that site.

    So what I need is that if I type 'y' in a cell from C (on any of the first 3 sheets), the corresponding description in cell B is transferred to Sheet 4.

    Does this make sense? Please let me know if you need more detail or what I can do make this work.

    Thanks in Advance!
    Last edited by iamonfire; 06-30-2011 at 06:57 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Transferring data from cells to another sheet if criteria is met

    of course everything is possible but I think, but I think you gave us insufficient data.
    As I understood you will tape "Y" in column C (sheet 1 or 2 or 3) and then you want to data from column B of current row in active sheet be copy automaticaly to sheet 4, am I right ?
    Where data should be copy, to first empty row in sheet4?

    The best way will be if you attach your workbook with dummy data and description.

    Best Regards

  3. #3
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    I'll post the file as soon as I receive it from my colleague.

    Cheers

  4. #4
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    OK I've attached the file. It appears that the table is a bit more complicated then I expected. I have removed all the text.

    So to clarify: I need that when a box is ticked, its corresponding description on Sheet 1 (Red list) is transferred under the Red list on Sheet 4 (Appendix 2). All subsequent checks marks from the red list are added under that same heading on Sheet 4. The same is needed for Sheets 2 and 3. That is to say, if a box is ticked on the Green list, it is added under the Green List in Appendix too. Same goes for the Amber list.

    Can you make it so I can click and un-click the cells, similar like you did for dave.carr earlier today?


    Thanks again!!!
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Transferring data from cells to another sheet if criteria is met

    only one box in each colour could be selected or even all of them ?
    I discover that R1 starts in row 16, A1 starts in row 15, G1 starts in row 14 (it would be better if starting row will be the same)

    A question about Sheet4. All listing have to start in row 35 ?

  6. #6
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    All possible combinations between red, amber and green can be selected. The selected descriptions should start in row 35. It may be easier if on sheet 4 the green, amber and red are in columns A, B and C, but they must begin there, because there is text in the rows above. I sent a new file with the changes made. Will I be able to modify the code to transfer just the abbreviations instead of the descriptions?

    Thanks
    Attached Files Attached Files
    Last edited by iamonfire; 06-29-2011 at 01:49 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Transferring data from cells to another sheet if criteria is met

    Hi iamonfire,

    I change a bit your worksheets to normalize them (multi rows I replaced with one row with word-wrap; delete column F from Red List [check list was in column G], now 1,2,3 sheet looks the same)

    Check if attached file cover your needs - to sheet4 for now only description from columns B is copy in time of selecting in column F.
    Whole code is in "ThisWorkbook" code.

    Best Regards
    Attached Files Attached Files
    Last edited by maczaq; 06-30-2011 at 03:30 AM.

  8. #8
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    This is perfect. You're a genius. Thank you so much. One quick question: how could I modify the code so that the abreviations (i.e R1, G2, A3 etc) are transferred instead of the entire descriptions?

  9. #9
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Transferring data from cells to another sheet if criteria is met

    it would be easy just replace one char in this code
        Do Until sh.Cells(r, 2).Value = ""
            If sh.Cells(r, 6).Value = "a" Then
              sh.Range("B" & r).Copy Sheet4.Range(col & rr) ' here B is a surce Column just replace with other column to get other source value
              rr = rr + 1
            End If
          r = r + 1
        Loop
    Best Regards

  10. #10
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    This is excellent. Thanks for making me understand!

  11. #11
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    What changes do i need to make if, on sheet 4, I want the Red, Amber and Green lists one on top of each other (all in column A instead of A, B and C)? I tried:

    Select Case sh.Name
    Case "Red List":
    Sheet4.Range("A37:A43").ClearContents 'clear sheet4 column A rows 37 to 43
    col = "A"

    Case "Amber List":
    Sheet4.Range("A45:A50").ClearContents 'clear sheet4 column B rows 45 to 50
    col = "A"

    Case "Green List":
    Sheet4.Range("A51:A57").ClearContents 'clear sheet4 column C rows 51 to 57
    col = "A"
    End Select

    But it's not working...any suggestions?

  12. #12
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Transferring data from cells to another sheet if criteria is met

    whole working code for you
    replace previous one with this:
    Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)
    If Target.Rows.Count = 1 And Target.Columns.Count = 1 And Target.Column = 6 Then
        If Target.Row > 15 And Target.Offset(, -4).Value <> "" Then
            If Target.Value = "a" Then
                Target.Value = ""
            Else
                Target.Value = "a"
            End If
            Target.Offset(, 1).Select
            
            updateSheet4 'sh 'run copy from activesheet to sheet4
        End If
    End If
    End Sub
    
    Sub updateSheet4()
    Dim r, rr As Integer 'row index for Checklist and sheet4
    rr = 36
    Sheet4.Range("A36:A200").Delete shift:=xlUp 'use range which will be bigger then you ever need for write all results in sheet4
    
    Dim sh 'memory holds your source sheets names; you can add here more if you want but make sure that you add here name which exists
    sh = Array("Red List", "Amber List", "Green List")
    
    For i = 0 To UBound(sh) 'loop through all sheets mentioned in array
     r = 16 'set start row index
      With Sheet4.Cells(rr, 1)
        .Value = sh(i) 'write sheet name
        .Font.FontStyle = "Bold" 'set font to bold 
        .Font.Size = 14 'set font size
      End With
      rr = rr + 1
    
        Do Until Sheets(sh(i)).Cells(r, 2).Value = ""
            If Sheets(sh(i)).Cells(r, 6).Value = "a" Then
              Sheets(sh(i)).Range("A" & r).Copy Sheet4.Range("A" & rr) 'copy values from source sheet column A to sheet4 column A
              rr = rr + 1 'increse destination row
            End If
          r = r + 1 'increase source row
        Loop
    Next i
    End Sub
    Best Regards
    MaczaQ
    Last edited by maczaq; 06-30-2011 at 12:26 PM. Reason: set comments

  13. #13
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    Thanks MaczaQ. This is really good stuff. I have text underneath the lists on sheet 4. How do I keep it from getting deleted when I click a box? Or better yet, how can I have the text scroll down along with the lists?

  14. #14
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Transferring data from cells to another sheet if criteria is met

    I think it is good question for separate thread ;-)

    this line is for delete in sheet4
    Sheet4.Range("A36:A200").Delete shift:=xlUp
    You can simply hash it of delete it or modify it, but whole copy process starts in row 36 (rr variable) of sheet4

    Best Regards

  15. #15
    Registered User
    Join Date
    06-29-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Transferring data from cells to another sheet if criteria is met

    But can I have the text in the code so that scrolls down along with the rest of the list? (i.e after Green list)??
    I've tried adding a new worksheet and adding it to the Array, then hiding the tab.
    Last edited by iamonfire; 07-01-2011 at 06:34 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.2.0