Copy Data from one Sheet to other sheet based on condition

SHEEPRAL

New Member
Joined
Mar 19, 2017
Messages
16
The below data is in one excel sheet
now I want to copy all data for Exchange House ABC and XYZ into Urgent sheet
and rest to non-urgent sheet.
Pls note the row number may very from Exchange house,
I need to copy data from Exchange House:( name of the exchange house )
till row where Exchange House Total: ( amt ) in mentioned
header 1header 2header 3
Product Type: Credit to Account -
Exchange House: abc
Transaction Date:30 Oct 2017
111
Day Total: 123,523.00 (INR)
Exchange House Total: 123,523.00(INR)
Exchange House: pqr
Transaction Date:30 Oct 2017
222
Day Total: 5,000.00 (INR)
Exchange House Total: 5,000.00(INR)
Exchange House:xyz
Transaction Date:27 Oct 2017
333
Day Total: 262,305.00 (INR)
Transaction Date:30 Oct 2017
444
555
Day Total: 3,012,573.00 (INR)
Exchange House Total: 3,274,878.00(INR)

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
As I mentioned in your previous post, you have provided a small data set for us to work with !!!
This will work on the dataset provided, but I'm sure your "real" data may prove problematic !

Code:
Sub MM1()
Dim lr As Long, r As Long, sr As Long, er As Long, br As Long, fr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Sheets("Urgent").Cells(Rows.Count, "A").End(xlUp).Row
lr3 = Sheets("Non Urgent").Cells(Rows.Count, "A").End(xlUp).Row
For r = 3 To lr
    If InStr(Range("A" & r).Value, "abc") Or InStr(Range("A" & r).Value, "xyz") Then
        sr = r
     End If
    If InStr(Range("A" & r).Value, "Exchange House Total") And sr <> 0 Then
        er = r
        lr2 = Sheets("Urgent").Cells(Rows.Count, "A").End(xlUp).Row
        Rows(sr & ":" & er).Copy Sheets("Urgent").Range("A" & lr2 + 1)
        sr = 0
        er = 0
    End If
    If InStr(Range("A" & r).Value, "pqr") Then
        br = r
     End If
    If InStr(Range("A" & r).Value, "Exchange House Total") And br <> 0 Then
        fr = r
        lr3 = Sheets("Non Urgent").Cells(Rows.Count, "A").End(xlUp).Row
        Rows(br & ":" & fr).Copy Sheets("Non Urgent").Range("A" & lr3 + 1)
        br = 0
        lr = 0
    End If
Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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