Based on the status, copy-paste entire row on another sheet

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
Dear Team,
I have one sheet where col H contains "open" or "close" status. What i'm trying in vba is wherever status is "open" in col H, all that records paste in "Sheet1".

Can anyone pls help on this vba code.. Thanks in advance..
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello VBABeginer,

Try the following code:-

Code:
Sub Test()

Application.ScreenUpdating = False

With Sheet1.Range("H1", Sheet1.Range("H" & Sheet1.Rows.Count).End(xlUp))
        .AutoFilter 1, "Open"
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
        .AutoFilter
End With

Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Hi, Thanks for immediate code assistance. But im trying to place name of the sheet instead of "Sheet1.Range",

for ex.- WBO is sheet name

Code:
With WBO.Range("H1", WBO.Range("H" & WBO.Rows.Count).End(xlUp))

and data starts from row 3 in WBO sheet
 
Last edited:
Upvote 0
Hello VBABeginer,

Try it as follows:-


Code:
Sub Test()

         [COLOR=#ff0000]Dim sh As Worksheet: Set sh = Sheets("WBO")[/COLOR]
        
Application.ScreenUpdating = False

With [COLOR=#ff0000]sh[/COLOR].Range("H2", [COLOR=#ff0000]sh[/COLOR].Range("H" & [COLOR=#ff0000]sh[/COLOR].Rows.Count).End(xlUp))
        .AutoFilter 1, "Open"
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
        .AutoFilter
End With

Application.ScreenUpdating = True

End Sub

I'm assuming that your headings are in row2 seeing that your data starts in row3.

It would still be wiser to use the sheet code rather than the sheet name.

What about the destination sheet (Sheet2)? Does it have a name also? If so, you can declare a variable for it and change Sheet2 in the code to suit. But make sure it is not the same variable as the source sheet(sh) : the parts in red font above.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Hi vcoolio,
Thanks for your reply. It's really nice of you..

I'm getting an error on-
.Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)

Error - Object required

one more, what is this --
(3)(2)
 
Last edited:
Upvote 0
Hello again,

I've just tested the code on a sample of what I assume your "WBO" sheet looks like and I am not receiving any errors.
Did you copy and paste the code into a module or did you type it in?

........or you are using a name for your destination sheet rather than the sheet code (Sheet2).
........or the sheet code is not Sheet2.
You'll need to clarify this.

one more, what is this -- (3)(2)
It is just an abbreviation.

It is the same as:

Code:
.Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count)[COLOR=#ff0000].End(xlUp).Offset(1)[/COLOR]

The (3) is the enumeration for the upward search from the bottom (xlUp) and the (2) is the enumeration for the offset of one row down from the previous row.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
Did you copy and paste the code into a module = Yes. I used module.


----
Yes, it works perfectly. The sheet i wanted to paste on, its like name is Sheet2 but its index name as Sheet3.

Thanks... This is great help..


 
Last edited:
Upvote 0
Hello VBABeginer,

Good to know its all working now.

You're welcome. I'm glad that I was able to help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,215,191
Messages
6,123,553
Members
449,108
Latest member
rache47

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