Solved

Find out the same 3-5 symbols in cells and mark cell

Posted on 2014-04-06
12
244 Views
Last Modified: 2014-05-14
I need to find the same 3-5 symbols or signs in 1 or 2 columns (but as one whole string), and mark them as duplicate in another column,
or just mark them with color, or maybe extract that same cells in other column.

example:

A
1 qw34-5-237890

2 zw34-59asdaz7890

3 zw98a-wrtqyy

I want to extract, mark with color or duplicate that cells (A1, A2) because they have the same "w34-5" symbols in one whole string, or "7890" not (A3), because he don't contain 3-4 symbols in 1 string just 2 "zw". Don't care if I have double check's same cell like in A1 and A2.

Thanks, Robin.
0
Comment
Question by:otpisani
  • 6
  • 2
12 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 39982021
This will put some matching indicator text in column B.
Option Explicit


Public Sub Q_28406055()
    Dim rng As Range
    Dim vData As Variant
    Dim lngRow As Long
    Dim lngLoop As Long
    Dim strText As String
    Dim oRE As Object
    Set oRE = CreateObject("vbscript.regexp")
    oRE.Pattern = "(.{3,5}).*?\^.*?(\1)"
    Set rng = ActiveSheet.Range(ActiveSheet.Range("A1"), ActiveSheet.Range("A1").End(xlDown))
    vData = rng.Value
    Application.ScreenUpdating = False
    For lngRow = 1 To UBound(vData) - 1
        For lngLoop = lngRow + 1 To UBound(vData)
            strText = vData(lngRow, 1) & "^" & vData(lngLoop, 1)
            If oRE.test(strText) Then
                rng.Cells(lngRow, 2).Value = "Matched with " & lngLoop
                rng.Cells(lngLoop, 2).Value = "Matched with " & lngRow
            End If
        Next
    Next
    Application.ScreenUpdating = True
End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 39982064
@otpisani

There are several different ways this problem could be solved.  My use of the regular expression engine is but one path.  The regexp engine in this environment stops when it finds the first matching substring.  If you needed to find all the matching substrings it will take more processing.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39986394
@Robin

Are you actively participating in this question thread?
0
 

Author Comment

by:otpisani
ID: 39986704
Hello,

Didn't have chance to try your code until now, and must admit it's working like a charm, just change {8,10}, because got to many marked cells in B column. Thanks a lot for your help.

Regards, Robin.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 45

Expert Comment

by:aikimark
ID: 39986804
so you didn't need to know how many matches? (and what substrings)
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39986811
Note: This could also be changed to only populate the B column in a forward or a backward direction, instead of populating both matching rows.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39995282
@Robin
it's working like a charm
Then it is time to close this question.
0
 

Author Comment

by:otpisani
ID: 39995916
Hello  aikimark,

Many thanks for solving my problem, you saved me lots of time.

Regards, Robin.
0
 

Expert Comment

by:otpisani1
ID: 40064162
Hello,

Need your help for solving problem with 3 sheets in excell.

Regards, Robin.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with Adding text from a form to a worksheet 5 37
Excel 2016 - Black cell borders 11 27
File not loading into PowerPivot 4 9
NEED TO UPDATE DATA IN EXCEL 18 29
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now