Results 1 to 16 of 16

Grab only necessary data make new sheet

Threaded View

  1. #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.

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