EXCEL find-copy-paste

5 pts.
Tags:
Microsoft Excel
VBA
Hello! Using VBA for first time, so everything is toughed for me.. The problem is: we need to find on the first sheet named SD in second column all cells contianing word 'drilling', then for each cell copy row which contains that cell and paste it in other sheet or book (doesn't matter). Please help me, the work is urgent and my code doesn't work Dim lCount As Long Dim rFoundCell As Range Sheet("SD").Activate Set rFoundCell = Range("B2") For lCount = 1 To WorksheetFunction.CountIf(Columns(2), "drilling") Set rFoundCell = Columns(2).Find(What:="drilling", After:=rFoundCell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, _ SearchDirection:=xlNext, MatchCase:=False) With rFoundCell .Select.Row .Selection.Copy Windows("Book1").Activate Columns("'lcount'").Select ActiveSheet.Paste Windows("SD").Activate End With Next lCount End Sub

Answer Wiki

Thanks. We'll let you know when a new response is added.

Better late than never.

Why can’t you just manually filter the data on that column? Anyway, here’s a sub that should work. Untested.

Sub LoopThroughColumn()

Dim lCount As Long
Dim rFoundCell As Range
Dim MyBook As Excel.Workbook
Dim NextRow As Long

Set MyBook = Workbooks(“Book1″)

NextRow = WorksheetFunction.CountA(MyBook.Sheets(1).Range(“B:B”))

Worksheets(“SD”).Activate

Set rFoundCell = Worksheets(“SD”).Range(“B2″)

For lCount = 1 To WorksheetFunction.CountIf(Columns(2), “drilling”)
Set rFoundCell = Columns(2).Find(What:=”drilling”, After:=rFoundCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)

rFoundCell.EntireRow.Copy MyBook.Sheets(1).Range(“A1″).Offset(NextRow, 0)

Next lCount

End Sub

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Snursmursik
    [...] Original post by unknown [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following