+ Reply to Thread
Results 1 to 16 of 16

Grab only necessary data make new sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Grab only necessary data make new sheet

    I have attached an example of what i am trying to accomplish. I have data that i have used formulas to grab. But it is all over the place and some are not even in the right columns etc. Sheet 1 describes how my formulas position the data i get. Sheet 4 is how i want it to look. So i am not sure if i can get a macro that puts all the data on another sheet or what? Any ideas would be great. Also i want it to add some information (see column g on sheet 4)

    Oh and only the highlighted data is what i need, i do not need the other stuff. Basically just time periods that have a start date and time and end time.

    Thank you in advance.
    Attached Files Attached Files
    Last edited by aehartle; 07-02-2010 at 04:04 PM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Grab only necessary data make new sheet

    Try this
    Option Explicit
    
    Sub TidySheet()
        Dim n As Integer
        Dim RowNo As Long, LastRow As Long
        Dim ColNo As Long, LastCol As Long
        Dim rng As Range
        Dim arrData() As Variant
        
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        On Error GoTo ResetApplication
        
        Set rng = ActiveSheet.UsedRange
        LastRow = rng.Rows.Count
        LastCol = rng.Columns.Count
        
        Range("A:A").Clear
        Range("A1") = "Employee ID"
        Range("B1") = "Name of Employee"
        
        For RowNo = LastRow To 3 Step -1
            ReDim arrData(0)
            n = 0
            For ColNo = 1 To LastCol
                If Cells(RowNo, ColNo) <> "" Then
                    arrData(n) = Cells(RowNo, ColNo)
                    n = n + 1
                    ReDim Preserve arrData(n)
                End If
            Next
            Select Case UBound(arrData)
                Case 0
                    Rows(RowNo).Delete
                Case 3
                    If Not IsNumeric(arrData(1)) Then
                        Rows(RowNo).Delete
                    Else
                        Rows(RowNo).Clear
                        Cells(RowNo, "C") = arrData(0)
                        Cells(RowNo, "D") = arrData(1)
                        Cells(RowNo, "F") = arrData(2)
                        
                        If Cells(RowNo, "F") < 0.5 Then
                            Cells(RowNo, "E") = arrData(0) + 1
                        Else
                            Cells(RowNo, "E") = arrData(0)
                        End If
                    End If
                Case 2
                    If Not IsNumeric(arrData(1)) Then
                        Range("A2") = arrData(0)
                        Range("B2") = arrData(1)
                    End If
                    Rows(RowNo).Delete
                Case Else
                    Rows(RowNo).Delete
            End Select
        Next
        Range("D:D,F:F").NumberFormat = "[$-F400]h:mm:ss AM/PM"
        Columns.AutoFit
        Rows.AutoFit
    
    ResetApplication:
        Err.Clear
        On Error GoTo 0
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End Sub

    It's a bit of a guess, but the best I can do with the sample.
    N.B. it adds a day to the date where required

    Hope this helps

    [EDIT]

    Just noticed I had overwritten the BU sheet in the sample sheet.
    Attached Files Attached Files
    Last edited by Marcol; 06-28-2010 at 02:47 PM. Reason: Workbook replaced
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Grab only necessary data make new sheet

    cant see anything in terms of functions on sheet1! what did you use?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    My functions are not in sheet 1 as it would come up as Ref's so it is hard data. I tried the vba code...works kind of...i have multiple employees in the same sheet. The vba provided smashes them all as one employee.. Great start and works how i want it to..just need it to separate out the employees too.

    Thanks for helping...it currently takes FOREVER to sort now.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Grab only necessary data make new sheet

    A bit of guesswork!

    I assumed to be valid data each row should have three values.

    Start date, Start time, Finish time

    If the finish time is PM then the missing column Finish Date = Start Date
    If the finish time is AM then the missing column Finish Date = Start Date + 1

    I also assumed there was only one employee involved.

  6. #6
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    any luck with the new info macrol? I really appreciate it.

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Grab only necessary data make new sheet

    Try this
    Option Explicit
    
    Sub TidySheet()
        Dim n As Integer
        Dim RowNo As Long, LastRow As Long
        Dim ColNo As Long, LastCol As Long
        Dim rng As Range
        Dim arrData() As Variant
        
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        On Error GoTo ResetApplication
        
        Set rng = ActiveSheet.UsedRange
        LastRow = rng.Rows.Count
        LastCol = rng.Columns.Count
        
        Range("A:A").Clear
        Range("A1") = "Employee ID"
        Range("B1") = "Name of Employee"
        
        For RowNo = LastRow To 3 Step -1
            ReDim arrData(0)
            n = 0
            For ColNo = 1 To LastCol
                If Cells(RowNo, ColNo) <> "" Then
                    arrData(n) = Cells(RowNo, ColNo)
                    n = n + 1
                    ReDim Preserve arrData(n)
                End If
            Next
            Select Case UBound(arrData)
                Case 0
                    Rows(RowNo).Delete
                Case 3
                    If Not IsNumeric(arrData(1)) Then
                        Rows(RowNo).Clear
                        Cells(RowNo, "A") = arrData(0)
                        Cells(RowNo, "B") = arrData(1)
                    Else: IsNumeric (arrData(1))
                        Rows(RowNo).Clear
                        Cells(RowNo, "C") = arrData(0)
                        Cells(RowNo, "D") = arrData(1)
                        Cells(RowNo, "F") = arrData(2)
                        
                        If Cells(RowNo, "F") < 0.5 Then
                            Cells(RowNo, "E") = arrData(0) + 1
                        Else
                            Cells(RowNo, "E") = arrData(0)
                        End If
                    End If
                Case 2
                    If IsNumeric(arrData(1)) Then
                        Rows(RowNo).Delete
                    Else
                        Rows(RowNo).Clear
                        Cells(RowNo, "A") = arrData(0)
                        Cells(RowNo, "B") = arrData(1)
                    End If
                Case Else
                    Rows(RowNo).Delete
            End Select
        Next
        Range("D:D,F:F").NumberFormat = "[$-F400]h:mm:ss AM/PM"
        Columns.AutoFit
        Rows.AutoFit
    
    ResetApplication:
        Err.Clear
        On Error GoTo 0
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End Sub

    Is that any better?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    I regret to inform you that it didn't work. The previous worked better it just didn't have the employee name inbetween the times.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Grab only necessary data make new sheet

    Have you down-loaded and tried the workbooks I posted, or just tried the code on a sheet of yours?

  10. #10
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    just the code in my sheets, i'll try the book

  11. #11
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    I tried your workbook but it still only has one person in there.

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Grab only necessary data make new sheet

    I tried your workbook but it still only has one person in there.
    As does your posted workbook ..

    You apparently have two in number employees.
    One called "Position", the other "Cashier N-4", both have the same ID "40002", or am I wrong?

    The first solution offered matched your requested table on Sheet "Sheet4" as far as was possible, note that there was no "split" in this requested table.

    The second used the only option that was left "split" on the aforesaid "Position", and "Cashier N-4"

    There are many clever people answering obsure questions on this forum, but as far as I am aware none of them have crystal balls.

    In the upper regions of my failing frame, I have two standard Mk1 eyeballs, they are, I regret to inform you, unable to glean any more from your brief.
    Perhaps the others I possess would do better if they were younger and fitter.

    Fix your problem at source!
    Last edited by Marcol; 06-28-2010 at 08:14 PM.

  13. #13
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Grab only necessary data make new sheet

    if you could just give original and desired results . then maybe functions can do it. vba certainly will given the correct info but no one knows exactly what you want( my crystal ball is at the opticians being re-ground as vari-focal )
    Last edited by martindwilson; 06-28-2010 at 08:21 PM.

  14. #14
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    Here is my example with 2 people. Sheet 1 is orignal data and sheet 4 is how i want it to look.
    Attached Files Attached Files

  15. #15
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Grab only necessary data make new sheet

    Okay here's another attempt.
    Option Explicit
    
    Sub TidySheet()
        Dim n As Integer
        Dim RowNo As Long, LastRow As Long
        Dim ColNo As Long, LastCol As Long
        Dim rng As Range
        Dim arrData() As Variant
        Dim strName As String
        Dim NameID As String
                        
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        On Error GoTo ResetApplication
        
        Range("K:K").Clear
        
        Set rng = ActiveSheet.UsedRange
        LastRow = rng.Rows.Count
        LastCol = rng.Columns.Count
        
        For RowNo = LastRow To 2 Step -1
            ReDim arrData(0)
            n = 0
            For ColNo = 1 To LastCol
                If Cells(RowNo, ColNo) <> "" Then
                    arrData(n) = Cells(RowNo, ColNo)
                    n = n + 1
                    ReDim Preserve arrData(n)
                End If
            Next
            Select Case UBound(arrData)
                Case 0
                    Rows(RowNo).Delete
                Case 3
                    If Not IsNumeric(arrData(1)) Then
                        Rows(RowNo).Clear
                        Cells(RowNo, "A") = arrData(0)
                        Cells(RowNo, "B") = arrData(1)
                    Else
                        Rows(RowNo).Clear
                        Cells(RowNo, "C") = arrData(0)
                        Cells(RowNo, "D") = arrData(1)
                        Cells(RowNo, "F") = arrData(2)
                        
                        If Cells(RowNo, "F") < 0.5 Then
                            Cells(RowNo, "E") = arrData(0) + 1
                        Else
                            Cells(RowNo, "E") = arrData(0)
                        End If
                    End If
                Case 2
                    If IsNumeric(arrData(1)) Then
                        Rows(RowNo).Delete
                    Else
                        If Cells(RowNo, "C") <> "" Then
                            NameID = arrData(0)
                            strName = arrData(1)
                            Rows(RowNo).Delete
                        Else
                            Rows(RowNo).Delete
                        End If
                    End If
                Case 1
                    If Cells(RowNo, "A") = "" Then
                        Rows(RowNo).Delete
                    End If
                Case Else
                    Rows(RowNo).Delete
            End Select
        Next
        Range("D:D,F:F").NumberFormat = "[$-F400]h:mm:ss AM/PM"
        Columns.AutoFit
        Rows.AutoFit
    
    ResetApplication:
        Err.Clear
        On Error GoTo 0
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End Sub

    Let me know how this one goes.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    05-12-2010
    Location
    Adrian, MI
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Grab only necessary data make new sheet

    Not sure but i think you solved it... It works excellent from what i can see

+ 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