Find then paste

T

Teddy

Sub FindPaste()

Application.ScreenUpdating = False
With Sheets("Statement")
With .Range("B3", .Range("B" & .Rows.Count).End(xlUp))
.Offset(-1).Resize(.Rows.Count + 1).AutoFilter _
Field:=1, Criteria1:="Agent"
On Error Resume Next
Sheets("Examine").Range("O1:AG1").Copy _
Destination:=.Offset(, 13).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
.AutoFilterMode = False
End With
Application.ScreenUpdating = True

End Sub


My goal is to create a macro that will look in Column B of worksheet
“Statement†,starting in row 3, for the text “Agentâ€. When that text is
found I would like to copy that row Columns O:AG and then paste it into the
range O1:G1 of worksheet “Examine.â€

The macro above will find the text “Agent†in Column B and then paste the
range from worksheet “Examine†into it, but I am trying to do the opposite.
I want to copy from random range based on text in worksheet “Statementâ€
Column O:AG and paste the data into specific range in worksheet “Examineâ€
O1:AG1. I gladly welcome any help. Thank you.
 
P

Per Jessen

Hi

In the 'Copy' statement you have to switch CopyRng and Destination range.
The macro is changed as I would write it, but not tested:

Sub FindPaste()
Dim FilterRng As Range
Dim CopyRng As Range
Application.ScreenUpdating = False

With Sheets("Statement")
Set FilterRng = .Range("B2", .Range("B" & Rows.Count).End(xlUp))
Set CopyRng = .Range("B3", .Range("B" & Rows.Count).End(xlUp))
End With

FilterRng.AutoFilter Field:=1, Criteria1:="Agent"
If CopyRng.SpecialCells(xlCellTypeVisible).Rows.Count > 0 Then
CopyRng.SpecialCells(xlCellTypeVisible).Offset(0, 13).Resize _
(CopyRng.SpecialCells(xlCellTypeVisible).Rows.Count, 19).Copy _
Destination:=Sheets("Examine").Range("O1")
End If

Sheets("Statement").AutoFilterMode = False
Application.ScreenUpdating = True
End Sub

Regards,
Per
 
T

Teddy

Sweet. Thank you. Very very close. Y:AG from "Statement" is getting pasted
into O1:Y1 of "Examine".

I am aiming for O:AG of "Statement" to get into O:AG of "Examine". Any
input is appreciated.
 
P

Per Jessen

It is working on my test data, do you by chance have any hidden columns,
when you run the macro?
 

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