In Sheet1, A:D has data about this year’s clients and column E has names of last year’s clients. Sheet2 is where new clients' data need to be copied.
With the below code, I'm trying to paste new 2022 clients' data (A:D) to non-filled cells of Sheet2 in columns A:D. the condition is if A2<>E2:E20 then paste A2:D2 into Sheet2 non-filled row.
but I'm getting run-time error 104: "you can't paste this here because the copy area and paste area aren't the same sizes. Select just one cell in the paste area or an area that's the same size, and try pasting again." and the VBA line "ActiveSheet.Paste" is gets yellow highlighted when I click the command button.
I don't understand why.
Sheet2 shows the desired outcome where green highlighted rows are new clients.
With the below code, I'm trying to paste new 2022 clients' data (A:D) to non-filled cells of Sheet2 in columns A:D. the condition is if A2<>E2:E20 then paste A2:D2 into Sheet2 non-filled row.
but I'm getting run-time error 104: "you can't paste this here because the copy area and paste area aren't the same sizes. Select just one cell in the paste area or an area that's the same size, and try pasting again." and the VBA line "ActiveSheet.Paste" is gets yellow highlighted when I click the command button.
I don't understand why.
Sheet2 shows the desired outcome where green highlighted rows are new clients.
VBA Code:
Private Sub CommandButton1_Click()
c = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
cc = Worksheets("Sheet1").Cells(Rows.Count, 5).End(xlUp).Row
For j = 1 To c
For jj = 1 To cc
If Worksheets("Sheet1").Cells(j, 1).Value <> Worksheets("Sheet1").Cells(jj, 5).Value Then
Worksheets("Sheet1").Range("a" & i & ":d" & i).Copy
Worksheets("Sheet2").Activate
b = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet2").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Sheet1").Activate
End If
Next: Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Sheet1").Cells(1, 1).Select
End Sub
Worksheets.xlsm | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | 2022 Clients | 2022 Data | 2022 Data2 | 2022 Data3 | 2021 Clients | ||
2 | Michael | 1234 | 1234 | 2345 | James | ||
3 | Sarah | 4321 | 54 | 67 | Sam | ||
4 | Mary | 9876 | 0 | 34 | Peter | ||
5 | Rachel | 5678 | 12 | 45 | Shaw | ||
6 | Anna | 7834 | 23 | 0 | Sally | ||
7 | Monica | 2356 | 45 | 45 | Michelle | ||
8 | Charles | 1234 | 0 | 0 | Ivona | ||
9 | Peter | 6543 | 23 | 0 | Anna | ||
10 | Anthony | 1234 | 23 | 0 | Claire | ||
11 | Ben | 1234 | 56 | 34 | Ben | ||
12 | Elizabeth | 6543 | 0 | 78 | Michael | ||
13 | Wong | 1276 | 23456 | 12 | David | ||
14 | Sally | 9854 | 23 | 56 | Annaleise | ||
15 | Jay | 4325 | 8765 | 89 | Chris | ||
16 | Michelle | 1265 | 1256 | 64 | John | ||
17 | David | 1276 | 1234 | 3 | Bob | ||
18 | Jennifer | 1234 | 8765 | 56 | Anthony | ||
19 | Sue | 8765 | 34 | 78 | Sue | ||
20 | Ruba | 3254 | 23 | 9 | Robin | ||
21 | Henry | 9876 | 78 | 0 | |||
22 | Chloe | 3245 | 34567 | 6 | |||
23 | Candy | 2389 | 356 | 5 | |||
Sheet1 |
Worksheets.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | 2022 Clients | 2022 Data | 2022 Data2 | 2022 Data3 | ||
2 | Peter | 6543 | 23 | 0 | ||
3 | Sally | 9854 | 23 | 56 | ||
4 | Michelle | 1265 | 1256 | 64 | ||
5 | Anna | 7834 | 23 | 0 | ||
6 | Ben | 1234 | 56 | 34 | ||
7 | Michael | 1234 | 1234 | 2345 | ||
8 | David | 1276 | 1234 | 3 | ||
9 | Anthony | 1234 | 23 | 0 | ||
10 | Sue | 8765 | 34 | 78 | ||
11 | Sarah | 4321 | 54 | 67 | ||
12 | Mary | 9876 | 0 | 34 | ||
13 | Rachel | 5678 | 12 | 45 | ||
14 | Monica | 2356 | 45 | 45 | ||
15 | Charles | 1234 | 0 | 0 | ||
16 | Elizabeth | 6543 | 0 | 78 | ||
17 | Wong | 1276 | 23456 | 12 | ||
18 | Jay | 4325 | 8765 | 89 | ||
19 | Jennifer | 1234 | 8765 | 56 | ||
20 | Ruba | 3254 | 23 | 9 | ||
21 | Henry | 9876 | 78 | 0 | ||
22 | Chloe | 3245 | 34567 | 6 | ||
23 | Candy | 2389 | 356 | 5 | ||
Sheet2 |