Best approach (VBA) to search through a sheet for all matches to a selected range (ie. multiple cells)?

radiocam

New Member
Joined
Apr 18, 2018
Messages
2
Hi.
I have not tried coding this yet. As my (probably confused) title indicates, I'm looking for the brains trust here to point me in the right "method" direction, please.
I'd rate myself around intermediate in VBA, kind of dabble intensely from time to time, when I have a need. (Mostly hobby. occasionally work. This is an aid for my weekly volunteering gig.)
This is a snippet from one of a few spreadsheets, each can run to 1000-3000 rows. To give it flesh, these are groups of clues & words.
The spreadsheets have lots of duplicated groups. And I want to find and delete duplicate groups.

How I see it working is that I select a range (always in columns C,D, for example I may select C3:D11, a "group")
With the range selected, I'd run a macro to search through the spreadsheet and identify every range (group) that matches my selection exactly. (string content)
How I delete is less important. Rather than pulling the rug out from my search/find/whatever, I'd probably just blank out the found range and later do a "delete" pass.

So I guess that leads me to my question:
What is the best way to do a "range search ", identifying the possible 0 to n matches?
Are there any functions (native VBA OR worksheet) which can match/find on a range rather than a single cell?
My vanilla approach of course is to think: Looping within a loop, iterating over cell value comparison,s and breaking at first mismatch, etc.
But I was curious if there's some function that may be a cleverer way to do it.
What surprised me is that burning quite a bit of Google-mileage, I found no one else asking about searching for a multiple-cell range. (probably my poor searching)
Also: the groups are very informal, no fixed number of rows, and some "duplicates" may have just a small difference.
I'll leave that for V5, ha ha. For starters, exact matches are fine.
Any suggestions/thoughts much appreciated.
Thanks!


2024-04-17 14_51_59-Test-CrosswordDB-2022.xlsm - Excel.png
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Like this:
suppose selected range is from C3:D11
1- match C3 and D3 in sheet, get the match number, i.e, 10
2- match C4 and D4 in sheet, get the match number, i.e, 11.
If 11=10+1 then step 3
3 - ...C5 and D5....
similar to the end.
Suggest using VBA code.
If you need my assist, try to upload a link.
 
Upvote 0
Like this:*
suppose selected range is from C3:D11
1- match C3 and D3 in sheet, get the match number, i.e, 10
2- match C4 and D4 in sheet, get the match number, i.e, 11.
If 11=10+1 then step 3
3 - ...C5 and D5....
similar to the end.
Suggest using VBA code.
If you need my assist, try to upload a link.
Thanks, mate.
Yes, I am talking about VBA, and that's what I meant by my vanilla approach:
Finding a match, then comparing by cell in source and target ranges.
If all cells match then it's a hit, otherwise drop out at first mismatch and loop back to find next.
I was just wondering if there is some function that I don't know about.
Essentially, methods like Range.Find and WorksheetFunction.Match seem to work matching a data variant with one cell at a time in a range. It would be nice if there was a native function that you could pass a range and it would look through a worksheet for an identical range. Kind of like a pattern match.
Which would save me writing it, ha ha.
I already have some search routines that I wrote for these spreadsheets, and I know it should be relatively straightforward to tweak them and add a range-match function.
Just being lazy (and curious) ;)
Cheers, and thanks for your advice and offer of assistance.
 
Upvote 0

Forum statistics

Threads
1,223,935
Messages
6,175,493
Members
452,649
Latest member
mr_bhavesh

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