Copy and paste to second Sheet (Conditional)

Raph85

New Member
Joined
Dec 20, 2015
Messages
26
Hi Excel experts,

I have a data that has a dept code on it on column A and I would like to copy only the data on dept code 1 to sheet 2.

Could you please kindly share your expertise on the VBA code for this method.

Thank you.

Raphael.
 
Hi 'my answer is this',

Thank you so much for your help, the macros is worked perfectly and sorry for all the trouble as I'm still quite new to this forum.

Thanks
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Glad to see I was able to help you. I do notice your sort of new here and I'm sure you will see that questions asked with lots of details get you answers quicker.

If you want to delete the rows on sheet one after copying them just add the line of script to the new script you should see in my second posting. It's always good to try and read these scripts best you can that way you will get to a point where you can write great scripts yourself. Take care.
 
Upvote 0
Hi,

If I'm adding a few Sheet in front of Sheet 1, which instructions do I need to change as I tried to add a couple Sheet in before sheet 1 then it didn't copy any data to Sheet 2. I don't quite understand what is this instruction does " Lastrow = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1"

how do I figure out the Sheet index number on Lastrow = Sheets(2).

Sorry for all the questions.

Thank you
 
Upvote 0
Try this:
You will notice I changed the sheet names "CopyFrom" and "CopyTo"
You can change these sheet names to what you like.
This script is the one that will delete the rows in sheet ("CopyFrom') after copying the rows to sheet "CopyTo"

Code:
Sub FilterMini()
'Mod 3
Dim Lastrow As Long
Lastrow = Sheets("[COLOR="#FF0000"]CopyTo[/COLOR]").Cells(Rows.Count, "A").End(xlUp).Row + 1
    With Worksheets("[COLOR="#FF0000"]CopyFrom[/COLOR]").Range("A1").CurrentRegion
        .AutoFilter Field:=1, Criteria1:="1", Operator:=xlFilterValues
        .SpecialCells(xlCellTypeVisible).Copy Worksheets("[COLOR="#FF0000"]CopyTo[/COLOR]").Range("A" & Lastrow)
        .SpecialCells(xlCellTypeVisible).Delete
    
    End With
ActiveSheet.AutoFilterMode = False

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,146
Messages
6,129,142
Members
449,488
Latest member
qh017

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