I need to copy data from table below in workbook data.xlsb based on criteria TEAM and EPOCA) and paste it in another workbook (H2H.xlsm). I'm trying this vba code, to copy the data if matches criteria from colomn B and D, but only copy the first one (then need to repeat the same to copy from colomn B and E)
I find the code online and try to adpat for my case but without sucess.
Thanks in advance
criteria:
EPOCA = 2021-2022
TEAM = Dortmund
I find the code online and try to adpat for my case but without sucess.
Thanks in advance
criteria:
EPOCA = 2021-2022
TEAM = Dortmund
VBA Code:
Option Explicit
Sub getData()
Dim LastRow As Integer, i As Integer, erow As Integer
Dim TEAM As String
Dim EPOCA As String
TEAM = Range("B2").Value
EPOCA = Range("A2").Value
Application.Goto Workbooks("DATA.xlsb").Sheets("DATABASE").CELLS(1, 1)
LastRow = Workbooks("DATA.xlsB").Sheets("DATABASE").Range("A" & Rows.COUNT).End(xlUp).ROW
For i = 2 To LastRow
If CELLS(i, 2) = EPOCA And CELLS(i, 4) = TEAM Then
Range(CELLS(i, 1), CELLS(i, 37)).Select
Selection.COPY
Application.Goto Workbooks("H2H.xlsm").Sheets("SHEET1").CELLS(1, 1)
Worksheets("Sheet1").Select
erow = ActiveSheet.CELLS(Rows.COUNT, 1).End(xlUp).Offset(1, 0).ROW
ActiveSheet.CELLS(erow, 1).Select
ActiveSheet.Paste
'ActiveWorkbook.Save
'ActiveWorkbook.Close
Application.CutCopyMode = False
End If
Next i
End Sub
COD | EPOCA | DATA | casa | fora | C | F | HT C | HT F |
D1 | 2021-2022 | 22-08-2021 | Bayern Munich | FC Koln | 3 | 2 | 0 | 0 |
D1 | 2021-2022 | 22-08-2021 | Hoffenheim | Union Berlin | 2 | 2 | 2 | 1 |
D1 | 2021-2022 | 27-08-2021 | Dortmund | Hoffenheim | 3 | 2 | 0 | 0 |
D1 | 2021-2022 | 28-08-2021 | Bayern Munich | Hertha Berlin | 5 | 0 | 2 | 0 |
D1 | 2021-2022 | 28-08-2021 | FC Augsburg | Leverkusen | 1 | 4 | 1 | 2 |
D1 | 2021-2022 | 28-08-2021 | Stuttgart | Freiburg | 2 | 3 | 2 | 3 |
D1 | 2021-2022 | 28-08-2021 | FSV Mainz | Greuther Furth | 3 | 0 | 2 | 0 |
D1 | 2021-2022 | 28-08-2021 | FC Koln | Bochum | 2 | 1 | 0 | 0 |
D1 | 2021-2022 | 28-08-2021 | Bielefeld | E. Frankfurt | 1 | 1 | 0 | 1 |
D1 | 2021-2022 | 29-08-2021 | Union Berlin | Monchengladbach | 2 | 1 | 2 | 0 |
D1 | 2021-2022 | 29-08-2021 | Wolfsburg | RB Leipzig | 1 | 0 | 0 | 0 |
D1 | 2021-2022 | 11-09-2021 | RB Leipzig | Bayern Munich | 1 | 4 | 0 | 1 |
D1 | 2021-2022 | 11-09-2021 | Leverkusen | Dortmund | 3 | 4 | 2 | 1 |
D1 | 2021-2022 | 11-09-2021 | Freiburg | FC Koln | 1 | 1 | 0 | 1 |
D1 | 2021-2022 | 11-09-2021 | Hoffenheim | FSV Mainz | 0 | 2 | 0 | 1 |
D1 | 2021-2022 | 11-09-2021 | Union Berlin | FC Augsburg | 0 | 0 | 0 | 0 |
D1 | 2021-2022 | 11-09-2021 | Greuther Furth | Wolfsburg | 0 | 2 | 0 | 1 |
D1 | 2021-2022 | 12-09-2021 | Monchengladbach | Bielefeld | 3 | 1 | 1 | 1 |
D1 | 2021-2022 | 12-09-2021 | E. Frankfurt | Stuttgart | 1 | 1 | 0 | 0 |
D1 | 2021-2022 | 12-09-2021 | Bochum | Hertha Berlin | 1 | 3 | 0 | 2 |
D1 | 2021-2022 | 17-09-2021 | Hertha Berlin | Greuther Furth | 2 | 1 | 0 | 0 |
D1 | 2021-2022 | 18-09-2021 | Bayern Munich | Bochum | 7 | 0 | 4 | 0 |
D1 | 2021-2022 | 18-09-2021 | FSV Mainz | Freiburg | 0 | 0 | 0 | 0 |
D1 | 2021-2022 | 18-09-2021 | Bielefeld | Hoffenheim | 0 | 0 | 0 | 0 |
D1 | 2021-2022 | 18-09-2021 | FC Koln | RB Leipzig | 1 | 1 | 0 | 0 |
D1 | 2021-2022 | 18-09-2021 | FC Augsburg | Monchengladbach | 1 | 0 | 0 | 0 |
D1 | 2021-2022 | 19-09-2021 | Dortmund | Union Berlin | 4 | 2 | 2 | 0 |
D1 | 2021-2022 | 19-09-2021 | Stuttgart | Leverkusen | 1 | 3 | 1 | 2 |
D1 | 2021-2022 | 19-09-2021 | Wolfsburg | E. Frankfurt | 1 | 1 | 0 | 1 |
D1 | 2021-2022 | 24-09-2021 | Greuther Furth | Bayern Munich | 1 | 3 | 0 | 2 |
D1 | 2021-2022 | 25-09-2021 | Monchengladbach | Dortmund | 1 | 0 | 1 | 0 |
D1 | 2021-2022 | 25-09-2021 | Leverkusen | FSV Mainz | 1 | 0 | 0 | 0 |
D1 | 2021-2022 | 25-09-2021 | Hoffenheim | Wolfsburg | 3 | 1 | 1 | 1 |