How to Copy a row from sheet1 to sheet2 with "if statement"

francescoorsini

New Member
Joined
Oct 10, 2016
Messages
7
This below is the Sheet1

ModelBrandStatusQuantityMinimal Quantity
a1AsusIn stock21
a2SonyIn stock11
a3ToshibaTest31
a4FujitsuTest11

<tbody>
</tbody>

I want to separate in different Sheet according to status.If status=In stock then copy the row and paste it to Sheet2.If status=Test copy the row and paste it to Sheet3.

This below will be Sheet2
ModelBrandStatusQuantityMinimal Quantity
a1AsusIn stock21
a2SonyIn stock11

<tbody>
</tbody>


This below will be sheet3

ModelBrandStatusQuantityMinimal Quantity
a3ToshibaTest31
a4FujitsuTest11

<tbody>
</tbody>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Sub copyStuff()
Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
Set sh3 = Sheets(3) 'Edit sheet name
sh1.UsedRange.AutoFilter 3, "In stock"
sh1.UsedRange.Offset(1).SpecialCells(xlCellTypeVisible).Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2)
sh1.AutoFilterMode = False
sh1.UsedRange.AutoFilter 3, "Test"
sh1.UsedRange.Offset(1).SpecialCells(xlCellTypeVisible).Copy sh3.Cells(Rows.Count, 1).End(xlUp)(2)
sh1.AutoFilterMode = False
End Sub
 
Upvote 0
Can we do this without Code? Just with if statement?

I can't, but someone else might be able to. If nobody else jumps in today, just click 'Reply' and type 'Bump' in the Quick Reply box and post it. If no reply in two or three days. Start a new thread.
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,609
Members
449,174
Latest member
ExcelfromGermany

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