VBA to filter and copy/paste lines in excell sheet

nikanuka

New member
Joined
Feb 14, 2017
Messages
1
Reaction score
0
Points
0
Goal is to take results from Team 1 column listed in the worksheet which name is BEFORE hyphen (-) in sheet name, and take results from Team 2 column listed in the worksheet which name is AFTER hyphen (-)
sorry for complicated text, hope the video will help

View attachment Book1.xlsx
 
Works on the active sheet:
Code:
Sub blah()
zz = Split(ActiveSheet.Name, "-")
If UBound(zz) = 1 Then
  Team1 = Application.Trim(zz(0))
  Team2 = Application.Trim(Replace(zz(1), "$", "", , , vbTextCompare))

  AreaNo = 0
  For Each are In Columns("B:B").SpecialCells(xlCellTypeConstants, 2).Areas
    Set myrng = Nothing
    AreaNo = AreaNo + 1
    Select Case AreaNo
      Case 1
        For Each cll In are.Cells
          If Application.Trim(cll.Value) = Team1 Then
            If myrng Is Nothing Then Set myrng = cll Else Set myrng = Union(myrng, cll)
          End If
        Next cll
        If Not myrng Is Nothing Then
          myrng.EntireRow.Copy Cells(Rows.Count, 1).End(xlUp).Offset(3)
        End If
      Case 2
        For Each cll In are.Offset(, 1).Cells
          If Application.Trim(cll.Value) = Team2 Then
            If myrng Is Nothing Then Set myrng = cll Else Set myrng = Union(myrng, cll)
          End If
        Next cll
        If Not myrng Is Nothing Then
          myrng.EntireRow.Copy Cells(Rows.Count, 1).End(xlUp).Offset(2)
        End If

      Case 3
        For Each cll In are.Cells
          If Application.Trim(cll.Value) = Team1 Then
            If myrng Is Nothing Then Set myrng = cll Else Set myrng = Union(myrng, cll)
          End If
        Next cll
        If Not myrng Is Nothing Then
          myrng.EntireRow.Copy Cells(Rows.Count, 1).End(xlUp).Offset(2)
        End If
    End Select
  Next are
End If
End Sub
 
Back
Top