ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA to copy values IF (https://www.excelbanter.com/excel-discussion-misc-queries/191294-vba-copy-values-if.html)

Memphus01

VBA to copy values IF
 
How can I create a statement that will select all rows on sheet 1 that have
Value "X" (text) in Column B and then paste into Sheet 2, A2?

Ron de Bruin

VBA to copy values IF
 
Try this
http://www.rondebruin.nl/copy5.htm

Below the first macro you can read how to do it manual

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Memphus01" wrote in message ...
How can I create a statement that will select all rows on sheet 1 that have
Value "X" (text) in Column B and then paste into Sheet 2, A2?


Memphus01

VBA to copy values IF
 
Ron - thanks for your help --

it runs perfectly---but when I tried to step out on my own a bit and create
up to 8 criteria I am messing up somewhere---

in the line--

rng.AutoFilter Field:=1, Criteria1:="=Netherlands", Operator:=xlOr,
Criteria2:="=USA"

how would I add a third crtieria, etc? I tried the following:

rng.AutoFilter Field:=1, Criteria1:="=Netherlands", Operator:=xlOr,
Criteria2:="=USA", Operator:=xlOr, Criteria3:="=FRANCE" , Operator:=xlOr,
Criteria4:="=Germany"

but keep getting an error on the third Criteria---

Thanks

"Ron de Bruin" wrote:

Try this
http://www.rondebruin.nl/copy5.htm

Below the first macro you can read how to do it manual

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Memphus01" wrote in message ...
How can I create a statement that will select all rows on sheet 1 that have
Value "X" (text) in Column B and then paste into Sheet 2, A2?



Ron de Bruin

VBA to copy values IF
 
There is a Max of 2 when you use AutoFilter
You can use Advanced filter or use a helper column with

=OR(A2={"USA","USA2","USA3","USA4","USA5"})

Then use AutoFilter on that column

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Memphus01" wrote in message ...
Ron - thanks for your help --

it runs perfectly---but when I tried to step out on my own a bit and create
up to 8 criteria I am messing up somewhere---

in the line--

rng.AutoFilter Field:=1, Criteria1:="=Netherlands", Operator:=xlOr,
Criteria2:="=USA"

how would I add a third crtieria, etc? I tried the following:

rng.AutoFilter Field:=1, Criteria1:="=Netherlands", Operator:=xlOr,
Criteria2:="=USA", Operator:=xlOr, Criteria3:="=FRANCE" , Operator:=xlOr,
Criteria4:="=Germany"

but keep getting an error on the third Criteria---

Thanks

"Ron de Bruin" wrote:

Try this
http://www.rondebruin.nl/copy5.htm

Below the first macro you can read how to do it manual

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Memphus01" wrote in message ...
How can I create a statement that will select all rows on sheet 1 that have
Value "X" (text) in Column B and then paste into Sheet 2, A2?




All times are GMT +1. The time now is 06:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com