-1

Data Sample

I am trying to pull the following from each group of Numbers -

CHG000509443 05-16-2016 22:48:41 for the Requested
CHG000509443 05-17-2016 13:14:35 for the Approved

Note 1 - It is always the first Requested in each group - See CHG000509448

Note 2 - It is always the 0 duration Approved in each group - See CHG000510593

7
  • Can you provide an example of where you are pulling the data from? I assume your image is what you are trying to reproduce?
    – Eric F
    May 31, 2016 at 20:08
  • I pull the data from a different source and then play with it.
    – SOfanuser
    May 31, 2016 at 21:43
  • Sounds like a job for pivot table Jun 1, 2016 at 9:03
  • Also look into a =MATCH and =INDEX function used together. I don't think VBA is needed,
    – Eric F
    Jun 1, 2016 at 12:03
  • @EricF I know VBA isn't needed, but I was thinking more along the lines of frequency or sumproduct rather than index(match) Jun 1, 2016 at 17:26

1 Answer 1

0

This code in VBA will do it:

Public Sub ReqandAppr()
    '****************
    ' variables
    SourceSheet = "Sheet1" 'name of source sheet
    DestSheet = "Sheet2"   ' name of destination sheet
    columntocheck = 5  'Column to check "Requested" or "Approved"
    firstrow = 2 'first row in source sheet
    destrow = 1  'first row in destination sheet
    'end of variables
    '*******************
    Dim wkb As Workbook
    Dim wksSource, wksDest As Worksheet
    Set wkb = ThisWorkbook
    Set wkSource = wkb.Sheets(SourceSheet)
    Set wkDest = wkb.Sheets(DestSheet)
    wkDest.Rows.Clear
    totalrows = wkSource.Cells(Rows.Count, 1).End(xlUp).Row
    For i = firstrow To totalrows
        If wkSource.Cells(i, 1) <> wkSource.Cells(i - 1, 1) Then
            requestedfound = False
            approvedfound = False
        End If
        Select Case wkSource.Cells(i, columntocheck)
            Case "Requested"
                If requestedfound = False Then
                    wkSource.Rows(i).Copy Destination:=wkDest.range("A" & destrow)
                    requestedfound = True
                    destrow = destrow + 1
                End If
            Case "Approved"
                If approvedfound = False And wkSource.Cells(i, columntocheck - 1) = 0 Then
                    wkSource.Rows(i).Copy Destination:=wkDest.range("A" & destrow)
                    approvedfound = True
                    destrow = destrow + 1
                End If
        End Select
    Next i
End Sub

Open VBA/MAcros with ALT+F11, under ThisWorkbook insert a new module and paste the code on the right side.

Check the value of the variables and execute it.

5
  • Wow! I will give it a try! If it works, I am going to somehow find you and take care of you!!!!
    – SOfanuser
    Jun 1, 2016 at 15:45
  • 1
    @Ducatiduke that's an awkward way of saying you will upvote and accept the answer. Jun 1, 2016 at 17:27
  • Sorry! I am just very happy!
    – SOfanuser
    Jun 2, 2016 at 18:54
  • Hi! I finally got to this but i am pulling a run-time error "9" Subscript out of range when i run this as described above. It is pointing to the line "Set wkSource = wkb.Sheets(SourceSheet) onedrive.live.com/… I had to post the screen shots and the ss in a onedrive... For some reason, i cannot sign into imgur.
    – SOfanuser
    Jun 10, 2016 at 17:45
  • @Ducatiduke. You renamed Sheet1 to Page 1 but didn't change it in the variables area of the code. Besides that you don't have a second sheet (in variables it's called Sheet2). The code uses it to put the final results.
    – jcbermu
    Jun 13, 2016 at 8:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .