Copy cells from one sheet to another based on criteria

N

Nathalie

Hi,
I have accounting information on a sheet.
One column is the account, the next one is the date of the movement, the
next one is the amount, the last one is the comment.
I would like to copy to another sheet the cells with the amount and the
comment for one specified acount and dates included in one month.
Do you have some code for this? I need help.
thanks
Nathalie
 
J

JLGWhiz

You might have to change the sheet references to the actual sheet names, but
the code tested OK based on what you described. I suggest you test it on a
copy of the file before you install it for permanent use in the actual file.


Sub tract()
Dim lr As Long, c As Range, acctVar As Variant
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set srcRng = ActiveSheet.Range("A2:A" & lr)
acctVar = InputBox("Enter the account number to search.")
For Each c In srcRng
If c.Value = CLng(acctVar) Then
Range("A" & c.Row & ":D" & c.Row).Copy _
Sheets(2).Range("A" & Sheets(2).Range("A65536"). _
End(xlUp).Row + 1)
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top