Macro to copy data from sheet1 to sheet2 based on a criteria.

Kaiser Khan

New Member
Joined
Dec 19, 2013
Messages
12
I have two sheets.
First sheet contain this information.

BANK ACCOUNTS
COMPANYACCOUNTBANKSTATUS
000112584563BARCLIVE
000212865845HSBCLIVE
000245864856HSBCCLOSED

<tbody>
</tbody>








I want the second sheet to bring row automatically when status in the above table is changed to closed.

CLOSED ACCOUNTS
COMPANYACCOUNTBANKSTATUS
000145668555BARCCLOSED
000245684569HSBCCLOSED
000245867125HSBCCLOSED

<tbody>
</tbody>









So whenever an account is given status CLOSED in the table (Sheet 1) excel should create a new row in the table in Sheet 2 and copy the row from sheet1.

Hopefully it makes sense. Please help me on this guys.
Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
On sheet1 or the sheet tha has the raw data from where it would be copied, right click the Tab and select view code, paste the following code in there and see if it does what you want

1. I assumed the data starts at column A
2. the sheet that it is copied to is named sheet2, change as necessary

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim wks2 As Worksheet
    Set wks2 = Worksheets("Sheet2") 'change as necessary
    lastrow = Range("A" & Rows.Count).End(xlUp).Row
    If Not Intersect(Target, Range("D2: D" & lastrow)) Is Nothing Then
        If Target.Value = "CLOSED" Then
            Range(Cells(Target.Row, 1), Cells(Target.Row, 4)).Copy
            wks2.Activate
            lastrow2 = wks2.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row
            wks2.Range("A" & lastrow2).Select
            ActiveSheet.Paste
        End If
    End If
            
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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