VBA implementation random input combination code, query unique identification code

Source: Internet
Author: User

Record background:

You need to query the combination code in Excel, the corresponding unique identification code.

Example combination code: 4+5+6+9+1*2 Identification Code: A1

interface random input combination code: 1*2+4+5+6+9 output Identification code: A1

VBA implementation:

Private Sub CommandButton1_Click ()
Textbox2.value = ""
Dim str, Searchvalue
Dim I
i = 1
Searchvalue = Textbox1.value

Dim arrsearchvaluelist
Arrsearchvaluelist = Split (searchvalue, "+")
' MsgBox UBound (arrsearchvaluelist)-LBound (Arrsearchvaluelist)
Dim seardict
Set seardict = CreateObject ("Scripting.Dictionary")
Dim k&
For k = 0 to UBound (arrsearchvaluelist)
Seardict (Arrsearchvaluelist (k)) = ""

Dim Txtresult
Txtresult = Textbox2.value

For R = 1 to Worksheets (1). UsedRange.Rows.Count
str = Worksheets (1). Cells (R, 1). Value
Dim arrsourcevaluelist
Arrsourcevaluelist = Split (str, "+")

If (UBound (arrsearchvaluelist)-LBound (arrsearchvaluelist)) = (UBound (arrsourcevaluelist)-LBound ( Arrsourcevaluelist) Then
Dim J&, a&
A = 0
For j = 0 to UBound (arrsourcevaluelist)
If seardict.exists (Arrsourcevaluelist (j)) Then
A = a + 1
A = A-1
End If
If ((A-1) = (UBound (arrsearchvaluelist)-LBound (arrsearchvaluelist)) Then
If Txtresult = "Then
Txtresult = str
Txtresult = txtresult & "|" & Str
End If
End If
Set d = Nothing
End If
i = i + 1

Textbox2.value = Txtresult
End Sub

VBA implementation random input combination code, query unique identification code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.