Macro find and copy text by three conditions

HesterPrynne

New Member
Joined
Feb 20, 2017
Messages
42
Hi,

I'm trying to find two values in two different columns. From one column "Ac Desc"(D) I need to copy only rows where met such values among text "2603", "3739" and do not met "UAH". And in anothercolumn "Record Stat" (H) I need only rows with value "O". Macro should copy whole row which met all conditions on a new sheet with keeping formatting.

Thanks in advance!

For example

Column D Column H

Ac DescRecord Stat
CURRENT ACCOUNT - USD (26001)O - Do not copy
transit acc USD - (37393)O - To copy
TRANSIT ACCOUNT - USD (26030)O - To copy
SOCIAL INSURANCE ACC - UAH (26046)O - Do not copy
TYPE ACCOUNT - UAH (26003)C - Do not copy
CURRENT ACCOUNT - USD (26006)O - Do not copy
TRANSIT ACCOUNT - USD (26038)O - To copy
TYPE ACCOUNT - UAH (26000)O - Do not copy
CURRENT ACCOUNT - USD (26003)C - Do not copy
TRANSIT ACCOUNT - USD (26031)O - To copy
TRANSIT ACCOUNT - USD (26034)O - To copy
TRANSIT FOR PMNTS - UAH(26034)O - Do not copy
TRANSIT ACCOUNT - USD (26034)C - Do not copy

<tbody>
</tbody>




As of now Im using this code , but it can see only one condition:

Code:
Sub FindMe()
Dim intS As Integer
Dim rngC As Range
Dim strToFind As String, FirstAddress As String
Dim wSht As Worksheet


Application.ScreenUpdating = False


If Worksheets("Search Results").AutoFilterMode = True Then Worksheets("Search Results").AutoFilterMode = False
Worksheets("Search Results").Range("B2:H100000").ClearContents


intS = 2
'This step assumes that you have a worksheet named
'Search Results.
Set wSht = Worksheets("Search Results")
strToFind = "2603"


'Change this range to suit your own needs.
With Worksheets("2603").Range("D:D")
Set rngC = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngC Is Nothing Then
FirstAddress = rngC.Address
Do
rngC.EntireRow.Copy wSht.Cells(intS, 1)
intS = intS + 1
Set rngC = .FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress


Worksheets("Search Results").Range("H1").Select
Selection.AutoFilter
Worksheets("Search Results").Range("$B$1:$H$22610").AutoFilter Field:=7, Criteria1:="O"


End If
End With


End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Ac DescRecord Stat
CURRENT ACCOUNT - USD (26001)O - Do not copy
transit acc USD - (37393)O - To copy
TRANSIT ACCOUNT - USD (26030)O - To copy
SOCIAL INSURANCE ACC - UAH (26046)O - Do not copy
TYPE ACCOUNT - UAH (26003)C - Do not copy
CURRENT ACCOUNT - USD (26006)O - Do not copy
TRANSIT ACCOUNT - USD (26038)O - To copy
TYPE ACCOUNT - UAH (26000)O - Do not copy
CURRENT ACCOUNT - USD (26003)C - Do not copy
TRANSIT ACCOUNT - USD (26031)O - To copy
TRANSIT ACCOUNT - USD (26034)O - To copy
TRANSIT FOR PMNTS - UAH(26034)O - Do not copy
TRANSIT ACCOUNT - USD (26034)C - Do not copy
26033739O - To copy
TRANSIT ACCOUNT - USD (26034)1010
C - Do not copy00
transit acc USD - (37393)O - To copy
TRANSIT ACCOUNT - USD (26030)O - To copy
TRANSIT ACCOUNT - USD (26038)O - To copy
TRANSIT ACCOUNT - USD (26031)O - To copy
TRANSIT ACCOUNT - USD (26034)O - To copy
this macro produced the lower table
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 15/11/2017 by bob
'
'
Dim mycold(100), mycolh(100)
For j = 2 To 14
Cells(20, 1) = Cells(j, 4)
Cells(21, 1) = Cells(j, 8)
If Cells(20, 6) = 1 Then GoTo 10 Else GoTo 20
10 Sum = Sum + 1
mycold(Sum) = Cells(j, 4)
mycolh(Sum) = Cells(j, 8)
20 Next j
For k = 1 To 100
If mycold(k) = "" Then GoTo 999
Cells(k + 29, 4) = mycold(k)
Cells(k + 29, 8) = mycolh(k)
Next k
999 End Sub

<colgroup><col><col span="2"><col><col span="3"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
you have both O to copy and O do not copy, can you clarify please ?
If Column D = "2603" and <> "UAH" and Column H = "O" - it should copy it (Example TRANSIT ACCOUNT - USD (26030) - O)
If Column D = "3739" and <> "UAH" and Column H = "O" - it should copy it (Example transit acc USD - (37393) - O )

If Column D = "2603" and Column H = "C" - it should not copy it (Example TRANSIT ACCOUNT - USD (26030) - C)
If Column D = "3739" and Column H = "C" - it should not copy it (Example transit acc USD - (37393) - C )

If Column D = "2603" and Column H = "C" - it should not copy it (Example TRANSIT ACCOUNT - UAH (26030) - C or O - no matter)
If Column D = "3739" and Column H = "C" - it should not copy it (Example transit acc UAH - (37393) - C or O - no matter)

In
Column D there are many other codes like "2600", "2650", but macro should copy only "2603", "3739" and <> "UAH" with "O" status in Column H.

Hope it helps you)
 
Upvote 0
Result sould look like:
Ac DescRecord Stat
transit acc USD - (37393)O
TRANSIT ACCOUNT - USD (26030)O
TRANSIT ACCOUNT - USD (26038)O
TRANSIT ACCOUNT - USD (26031)O
TRANSIT ACCOUNT - USD (26034)O

<colgroup><col><col></colgroup><tbody>
</tbody>


Do not copy and to copy - its comments!
 
Upvote 0
now position clarified, try this

Ac DescRecord Stat
CURRENT ACCOUNT - USD (26001)O
transit acc USD - (37393)O
TRANSIT ACCOUNT - USD (26030)O
SOCIAL INSURANCE ACC - UAH (26046)O
TYPE ACCOUNT - UAH (26003)O
CURRENT ACCOUNT - USD (26006)O
TRANSIT ACCOUNT - USD (26038)O
TYPE ACCOUNT - UAH (26000)O
CURRENT ACCOUNT - USD (26003)C
TRANSIT ACCOUNT - USD (26031)O
TRANSIT ACCOUNT - USD (26034)O
TRANSIT FOR PMNTS - UAH(26034)O
TRANSIT ACCOUNT - USD (26034)O
26033739UAH
TRANSIT ACCOUNT - USD (26034)1001O
transit acc USD - (37393)O
TRANSIT ACCOUNT - USD (26030)O
TRANSIT ACCOUNT - USD (26038)O
TRANSIT ACCOUNT - USD (26031)O
TRANSIT ACCOUNT - USD (26034)O
TRANSIT ACCOUNT - USD (26034)O
this macro produced the lower table
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 15/11/2017 by bob
'
'
Dim mycold(100), recstat(100)
For j = 2 To 14
Cells(20, 1) = Cells(j, 4)
Cells(20, 8) = Cells(j, 8)
If Cells(20, 5) = 1 Then GoTo 10 Else GoTo 20
10 Sum = Sum + 1
mycold(Sum) = Cells(j, 4)
recstat(Sum) = Cells(j, 8)
20 Next j
For k = 1 To 100
If mycold(k) = "" Then GoTo 999
Cells(k + 29, 4) = mycold(k)
Cells(k + 29, 8) = recstat(k)
Next k
999 End Sub

<colgroup><col><col span="2"><col><col span="3"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,323
Members
449,154
Latest member
pollardxlsm

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