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:
My code copies the data for account 20110 to another worksheet then deletes it. If you don't want to copy it remove that line. If you want to find a different account change the filter criteria.
 
Upvote 0
Hi Andrew,

I got it :)....Please see below code. Thanks for your help :)

Copy

VBA Code:
    Range("A1").Select
    Set foundcell = Cells.Find(What:="Liability Account : 20110-", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If foundcell Is Nothing Then
    MsgBox "No Data for Account 20110"
    Exit Sub
    Else
    foundcell.Activate
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Sheets("20110 - Detailed Invoice Aging").Select
    Range("A2").Select
    ActiveSheet.Paste
    End If

Delete

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
    foundcell.Activate
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.EntireRow.Delete
    End If
   
    Range("A1").Select
    Set foundcell = Cells.Find(What:="Liability Account : 20310-0000", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If foundcell Is Nothing Then
    Else
    foundcell.Activate
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.EntireRow.Delete
    End If
   
    Range("A1").Select
    Set foundcell = Cells.Find(What:="Liability Account : 20320-0000", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If foundcell Is Nothing Then
    Else
    foundcell.Activate
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.EntireRow.Delete
    End If
 
Last edited by a moderator:
Upvote 0
Solution

Forum statistics

Threads
1,226,797
Messages
6,193,051
Members
453,772
Latest member
aastupin

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