1

Can you please help check the error with my code below ?

Sub copy_compare()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Set ws1 = Sheets("Sheet1")
    Set ws2 = Sheets("Sheet2")
    Dim sodong As Integer
    Dim i As Integer
    sodong = ws2.Columns("B").Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 To sodong
        If ws2.Columns(i, 3).Value = "NONE" Then
            ws2.Range("A" & i & ":B" & i).Copy
            'select the last row + 1 of sheet1 then paste
            ws1.Select
            Columns(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial
        Else
        End If
    Next i
End Sub

enter image description here

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
thangvc91
  • 323
  • 2
  • 10

2 Answers2

0

The error is not there but on the line above it.

If ws2.Columns(i, 3).Value = "NONE" Then

Change it to

If ws2.Cells(i, 3).Value = "NONE" Then
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • thank you , additional stuff I'm don't know how to solve it , can you please help ? I assume sheet A i don't know how many number row , but i wish i can select the last 10 rows , how to do that men ? – thangvc91 May 27 '21 at 06:18
  • Every new problem should be posted as a new question. `I assume sheet A i don't know how many number row` [THIS](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba) will help. – Siddharth Rout May 27 '21 at 06:29
0

As per Microsoft Docs, "columns" should only accept one parameter and system prompted message on screen when there are more than one parameter (i and 3) is provided. e.g. columns(i,3)

AprendizG
  • 1
  • 1