Comparing multiple ranges with conditional logic

Brad M

New Member
Joined
Apr 23, 2012
Messages
2
Hello,

I'm new to VB, so any pointers (beyond my specific question) are certainly appreciated. I need to:

[1] compare (row) ranges across two columns with an unequal number of rows (column A [number] to column C [number])
[2] save each result of [1] where there was a match in column B
[3] for each row where there was a match (now stored in B), compare the value from the same row in column D (date) with the same row of column F (date), and store the result in column E
[4] count and message box the final number of matches from column E

Data Example:

A B C D E F
----- ----- ----- ----- ----- -----
12345 match 12345 11/1/2011 match 11/1/2011
77777 34345 ... ...

A and C numbers match, so check same row date in D that does match date in E, place "match" in E, then count and display.

Sub other()
Dim range1, range2, range3, range4, range5, range6 As range
Dim x As Variant, y As Variant, z As Variant, a As Variant

Set range1 = range("A2:A4331")
Set range2 = range("B2:B4331")
Set range3 = range("C2:C1012")

Set range4 = range("D2:D4331")
Set range5 = range("E2:E4331")
Set range6 = range("F2:F1012")

For Each x In range1
For Each y In range3
If x = y Then x.Offset(0, 1) = "match"
Next y
Next x

' this completes step [2], but not sure how to code step [3]

???

c = Application.WorksheetFunction.CountA(range5)
MsgBox "Matches: " & (c)
End Sub

Thank you for any help!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Replying to self (edit time window expired).

Forgot to note:

* Excel 2010
* Windows 7

Anyone have any thoughts? More information needed? Anyone recommend the WorksheetFunction.Match Method for this?

Apologies that I can't post results of my code (other than success up to step [2]) - I'm just not sure about step [3] - tried an a additional For Each loop, but not sure how to reference the fact that I need to stay on the same row...
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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