Find and Copy

lakshmipathi123

Board Regular
Joined
Jul 10, 2012
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hi Experts,

Could you please provide me macro coding for Find and copy.

Here is an example

I have data around 15000 lines. I need segregate the data into 4 accounts. i.e.20310-0000,20320-0000,20110- and 20280.

Macro should find macro first line 20310-0000 copy till last line of 20310-0000 and paste into sheet 2

VBA Code:
Range("A1").Select
    Cells.Find(What:="Liability Account : 20110-", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
   
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Sheets("20110 - Detailed Invoice Aging").Select
    Range("A2").Select
    ActiveSheet.Paste


Thank you,
Lakshmipathi
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi Andrew,

Thanks for your reply.

Auto filter cant use bcoz it will not copy all the data....i need to copy all the data from first to last line. Will you able to help me with my request

Thank you,
 
Upvote 0
Hi Andrew,

Accounts will be in A column and related one account has Employee name,ID,Amount and aging. If we do filter will get only accounts. But i need Account+Employee name,ID,Amount and aging. Here is the code i used.

VBA Code:
Range("A1").Select
    Cells.Find(What:="Liability Account : 20110-", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
   
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Sheets("20110 - Detailed Invoice Aging").Select
    Range("A2").Select
    ActiveSheet.Paste
 
Last edited by a moderator:
Upvote 0
Try:

VBA Code:
Sub Test()
    With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:= _
            "=Liability Account : 20110-*", Operator:=xlAnd
        With .Parent.AutoFilter.Range
            With .Offset(1).Resize(.Rows.Count - 1)
                .Copy Sheets("20110 - Detailed Invoice Aging").Range("A2")
                .EntireRow.Delete
            End With
        End With
        .Parent.AutoFilterMode = False
    End With
End Sub
 
Last edited by a moderator:
Upvote 0
Hi Andrew,

Filter mode will not work for me....i need something like below code. But below code is not working for me...any suggestions.

VBA Code:
  If Cells.Find(What:="Liability Account : 20310-0000", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate Then
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.EntireRow.Delete
    Else
    MsgBox "Nodata"
    End If
   
    If Cells.Find(What:="Liability Account : 20320-0000", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate Then
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.EntireRow.Delete
    Else
    MsgBox "Nodata"
    End If
 
Last edited by a moderator:
Upvote 0
Hi,

I tried Ur code but it is copying filtered data. I need to find this account "Liability Account : 20310-0000" and activate from that line copy till last line of 20310-0000 data. I dont know how to attach my excel sheet to this thread. That will make u better understand.Right now am working on this code.

VBA Code:
Range("A1").Select
    Set foundcell = Cells.Find(What:="Liability Account : 20280-0000", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
   
    If foundcell Is Nothing Then
    Else
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    foundcell.Selection.EntireRow.Delete
    End If
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,216,046
Messages
6,128,489
Members
449,455
Latest member
jesski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top