+ Reply to Thread
Results 1 to 11 of 11

extracting info to another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-04-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    14

    extracting info to another worksheet

    Hey guys,

    I've got a problem with extracting information. I have attached an example of the worksheet I am currently working on.
    What I want is whenever the Status (Column H) is selected to "Closed", I want certain columns of that row (say E,G and H) to get extracted in Sheet3.

    I'm a newbie to Excel, so any help on this would be appreciated.

    Cheers,

    Pete.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: extracting info to another worksheet

    Try this:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    Dim NR As Long
    
    For Each Cell In Target
        If Not Intersect(Cell, Range("C3:C250,I3:I250")) Is Nothing Then
            With Cell.Offset(, 1)
                .Value = Time
                .EntireColumn.AutoFit
            End With
        ElseIf Cell.Column = 8 And Cell = "Closed" Then
            Cell.Offset(, 2) = Time
            With Sheets("Sheet3")
                NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                .Range("A" & NR).Value = Range("E" & Cell.Row).Value
                .Range("B" & NR).Resize(1, 2).Value = _
                    Range("G" & Cell.Row).Resize(1, 2).Value
            End With
        End If
    Next Cell
    
    End Sub

    This method allows you to change multiple cells at once and it will process them all correctly, instead of just exiting the sub.
    Attached Files Attached Files
    Last edited by JBeaucaire; 01-10-2011 at 10:30 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-04-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: extracting info to another worksheet

    Thanks JBeaucaire,

    Would it be possible to explain the lines:

    NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                .Range("A" & NR).Value = Range("E" & Cell.Row).Value
                .Range("B" & NR).Resize(1, 2).Value = _
                    Range("G" & Cell.Row).Resize(1, 2).Value
    Sorry to bother you, but I want to understand whats actually asking.

    Cheers,
    Pete
    Last edited by Rezez88; 01-10-2011 at 01:42 AM.

  4. #4
    Registered User
    Join Date
    01-04-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: extracting info to another worksheet

    Also, why is this line required?

    Cell.Offset(, 2) = Time
    Cheers
    Last edited by Rezez88; 01-10-2011 at 01:43 AM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: extracting info to another worksheet

    Looking at your sheet again, I noticed a problem formula in column I. The formula uses the TODAY() function to display a date. You do realize that each time you open the sheet all those formulas will update to display today's date, not the first day it was resolved?

    As such, since you're using VBA anyway, I'd remove the formula and let VBA enter the date, too. It's been added here along with the comments you've requested:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    Dim NR As Long
    
    For Each Cell In Target
        If Not Intersect(Cell, Range("C:C,I:I")) Is Nothing Then
            With Cell.Offset(, 1)       'using the cell to the right...
                .Value = Time           '...add the time
                .EntireColumn.AutoFit   'autofit that column
            End With
        ElseIf Cell.Column = 8 And Cell = "Closed" Then
            Cell.Offset(, 1) = Date     'add date one cell to the right, in column 9
            Cell.Offset(, 2) = Time     'add time two cells to the right, in column 10
            With Sheets("Sheet3")
                'find the next empty row on sheet3
                NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                'put the value from A into sheet3 column A
                .Range("A" & NR).Value = Range("E" & Cell.Row).Value
                'put the values from G:H into sheet3 columns B:C
                .Range("B" & NR).Resize(1, 2).Value = _
                    Range("G" & Cell.Row).Resize(1, 2).Value
            End With
        End If
    Next Cell
    
    End Sub

  6. #6
    Registered User
    Join Date
    01-04-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: extracting info to another worksheet

    JBeaucaire, you are honestly a legend mate!! Thanks for also pointing out the silly error I made with the time and providing me with a solution.

    I'm sorry if i'm asking for too much but is it possible to have closed items 'shifted' onto another sheet??
    What I mean is, at the moment I have a condensed summary on worksheet 3 and I also want the whole row I have closed to be able to be removed from the main sheet and onto another sheet at a later date, say ''removed faults' sheet. This sheet will keep adding the new 'closed' faults to the top of the row and in the mean time, once removed from the main sheet also get deleted from the summary sheet.

    Sorry if i'm not wording it properly, but any (more) help would be appreciated....

    Cheers,
    Pete

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: extracting info to another worksheet

    What/When/How do you see this movement being triggered?

    I would use a Worksheet_Activate on this "other sheet" that does an AutoFilter on the main sheet for the Faults and then copies them as a whole to the top of the "other sheet", deleting them from the main sheet, then turning off the AutoFilter. So any time you want to "move" the fault, you would need only to activate this "other sheet".

    Create a modified workbook and see if you can get an autofilter to copy the rows, we can tweak that together to make it cut/delete from the main sheet.

  8. #8
    Registered User
    Join Date
    01-04-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: extracting info to another worksheet

    No worries, thanks mate i'll get working on that.. (it might take a little while though)

    Just another question in the mean time. Is there any way to get my priorities coloured? All in white font, with "HIGH" filled in red, "MEDIUM" filled in blue, and "LOW" filled in light green. The problem is I already have three conditions (formatting) running and I don't know how I would code the above? Case statement possibly?? How would I choose the colours in code??

    Cheers,
    Pete

  9. #9
    Registered User
    Join Date
    01-04-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: extracting info to another worksheet

    Guys,

    I have attached where I'm at atm. I've added a delete row macro which is assigned to the delete row button.
    Can you have a look and let me know whether this is the best way to do it or not. When the row is 'Closed', it is saved in the Summary Sheet (info required by externals). When the faults are resolved, I can delete the row and it should be moved to the Removed faults sheet and consequently removed from the Summary sheet.
    There is still a problem with the file, it looks like there might be a conflict with the code you provided? Please let me know. Any help from anyone will be appreciated.

    Cheers,
    Pete
    Attached Files Attached Files

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: extracting info to another worksheet

    The worksheet change event I gave you didn't include making more changes to the active sheet. When you do that, you have to turn off macros first, else the ws_change macro can keep triggering itself over and over...could be problematic.

    My edits on your updated version of that macro:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    Dim NR As Long
    Application.EnableEvents = False
    
    For Each Cell In Target
        If Not Intersect(Cell, Range("C:C,I:I")) Is Nothing Then
            With Cell.Offset(, 1)       'using the cell to the right...
                .Value = Time           '...add the time
                .EntireColumn.AutoFit   'autofit that column
            End With
        ElseIf Cell.Column = 8 And Cell = "Closed" Then
            Cell.Offset(, 1) = Date     'add date one cell to the right, in column 9
            Cell.Offset(, 2) = Time     'add time two cells to the right, in column 10
            With Sheets("Summary Sheet")
                'find the next empty row on sheet3
                NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                'put the value from A into sheet3 column A
                .Range("A" & NR).Value = Range("C" & Cell.Row).Value
                'put the values from G:H into sheet3 columns B:C
                .Range("B" & NR).Resize(1, 2).Value = _
                    Range("E" & Cell.Row).Resize(1, 2).Value
                .Range("D" & NR).Value = Range("I" & Cell.Row).Value
            End With
        ElseIf Cell.Column = 8 And Cell = "Open" Or Cell = "In Progress" Then
            Cell.Offset(, 1).Resize(1, 2) = "N/A"
        ElseIf Cell.Column = 8 And Cell = "" Then
            Cell.Offset(, 1).Resize(1, 2) = ""
        End If
        
    Next Cell
    
    Application.EnableEvents = True
    End Sub

    Other macro edits:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Cells.Count > 1 Then Exit Sub
        If Target.Column = 3 Then
            Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
            Calendar1.Top = Target.Top + Target.Height
            Calendar1.Visible = True
        ' select Today's date in the Calendar
            Calendar1.Value = Date
        ElseIf Calendar1.Visible Then Calendar1.Visible = False
        End If
    End Sub
    Sub DeleteLine()
    
    '   clear date, severity, comments, workorder, flags
        ActiveCell.Resize(1, 9).ClearContents
    
    End Sub
    Sub DeleteEntireRow()
    
    ' Delete Date, car num, oscar pos, actual pos,temp,severity,hbd pos,loaded empty,sap,notify num,car tsl
        ActiveCell.Resize(1, 11).Delete Shift:=xlUp
        
    End Sub

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: extracting info to another worksheet

    Here's more, this adds moving the row to Removed Faults when it's set as "closed".
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    Dim NR As Long
    Application.EnableEvents = False
    For Each Cell In Target
        If Not Intersect(Cell, Range("C:C,I:I")) Is Nothing Then
            With Cell.Offset(, 1)       'using the cell to the right...
                .Value = Time           '...add the time
                .EntireColumn.AutoFit   'autofit that column
            End With
        ElseIf Cell.Column = 8 And Cell = "Closed" Then
            Cell.Offset(, 1) = Date     'add date one cell to the right, in column 9
            Cell.Offset(, 2) = Time     'add time two cells to the right, in column 10
            With Sheets("Summary Sheet")
                'find the next empty row on sheet3
                NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                'put the value from A into sheet3 column A
                .Range("A" & NR).Value = Range("C" & Cell.Row).Value
                'put the values from G:H into sheet3 columns B:C
                .Range("B" & NR).Resize(1, 2).Value = _
                    Range("E" & Cell.Row).Resize(1, 2).Value
                .Range("D" & NR).Value = Range("I" & Cell.Row).Value
            End With
            With Sheets("Removed Faults")
                .Range("B3:L3").Insert xlShiftDown
                Range("B" & Cell.Row).Resize(1, 11).Copy
                .Range("B3").PasteSpecial xlPasteValues
                .Range("B3").PasteSpecial xlPasteFormats
                Range("B" & Cell.Row).Resize(1, 11).Delete xlShiftUp
            End With
            Range("B4", Range("B" & Rows.Count).End(xlUp)).FormulaR1C1 = _
                "=IF(R[-1]C12=""Kris Kilian"",ROW(R[-2]C2),IF(R[-1]C12=""Vladimir Mazur"",ROW(R[-2]C2),IF(R[-1]C12=""Mindy Donnelly"",ROW(R[-2]C2),IF(R[-1]C12=""Harun Trefry"",ROW(R[-2]C2),IF(R[-1]C12="""","""",IF(R[-1]C12=""Other"",ROW(R[-2]C2)))))))"
    
        ElseIf Cell.Column = 8 And Cell = "Open" Or Cell = "In Progress" Then
            Cell.Offset(, 1).Resize(1, 2) = "N/A"
        ElseIf Cell.Column = 8 And Cell = "" Then
            Cell.Offset(, 1).Resize(1, 2) = ""
        End If
        
    Next Cell
    
    Application.EnableEvents = True
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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