Very new to VBA. I need to copy all paid account numbers into Column A of the current sheet. The Accounts sheet has the account numbers in column A and in column B either "Paid" or "Unpaid". I just keep getting error after error and I'm not sure if I'm fixing it or making it worse, but the last error I couldn't get past was for the line Cells(t,1).Value =i: "Application Defined or Object Defined Error."
Sub Button1_Click()
Dim t As Integer
Dim i As Range
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Sheets("Accounts")
Dim rng As Range
Set rng = Worksheets("accounts").Range("A:A")
'starting with cell A2
target = 2
'For each account number in Accounts
For Each i In rng
'find if it's paid or not
If Application.WorksheetFunction.VLookup(i, sheet.Range("A:B"), 2, False) = "PAID" Then
'if so, put it in the target cell
Cells(t, 1).Value = i
t = t + 1
End If
Cells(t, 1).Value = i
t = t + 1
Next i
End Sub
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire