Find an exact match of a number into a text string with random letters and numbers





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have only numbers in Sheet2 in col.B starting with B2: 81, 102 (in B3), 104 (in B4), etc, and in Sheet1 in col.A starting with A2, mixed text with numbes with no logical place text like: abc813bnm 12mn (in A2), fgh 81lkj 45ol (in A3), ert1042hji (in A4), and so on. I need to search each number from col.B/Sheet2 in col.A/Sheet1 and write in is an exact match on the same row in col.Q let's say. he exact match of first no.81 is in A3 (fgh 81lkj 45ol), but not in A2 (abc813bnm 12mn) where it is inside of 813 string. In my code 81 (and not only) it is "found" and in the cell with 81 and in a cell with 813, and I do not want that:



Sub SearchLCL()



Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False

Dim LCL1 As String
Dim LCL2 As String
'Dim answer As String
Dim c As Range
Dim counter As Long
Dim totalLCL1 As Long
Dim totalLCL2 As Long

counter = 2

'Sheets("MailElibLCL").Select 'Sheet2
'Sheets("lucrari 2017").Select 'Sheet1

totalLCL2 = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
totalLCL1 = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row

'totalLCL2 = N
'totalLCL1 = N3

For I = 2 To totalLCL2
'answer = Worksheets("hedis1").Range("h" & counter).Value
LCL2 = Worksheets("Sheet1").Range("A" & counter).Value
'LCL2 = "=MID(Worksheets.Sheet1.Range(""A"" & counter),SEARCH(LCL1,Worksheets.Sheet1.Range(""A"" & counter)),LEN(LCL1))"
k = "Q" & counter
For j = 2 To totalLCL1
LCL1 = Worksheets("Sheet2").Range("B" & j).Value

If InStr(1, LCL2, LCL1, vbTextCompare) > 0 Then
Debug.Print LCL1

'If LCL1 = LCL2 Then
'If answer = "Yes" Then
For Each c In Worksheets("Sheet1").Range(k)

'c.Value = Mid(LCL2, Search(LCL1, LCL2), Len(LCL1))
'c.Formula = "=MID(LCL2,INSTR(LCL1,LCL2),LEN(LCL1))"
'c.EntireRow.Interior.Color = 6 ' Change the number to match the desired color.
c.Value = LCL1 '& vbLf & Date 'Now (si ora minute secunde)
'c.Interior.Color = 5296210 ' Change the number to match the desired color.

Next c
'End If
'End If
End If
Next j
counter = counter + 1
Next I


'Else
'Call ScrieMailElib
'End If



On Error GoTo 0



Application.EnableEvents = True
Application.DisplayStatusBar = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub



Thank you.










share|improve this question































    1















    I have only numbers in Sheet2 in col.B starting with B2: 81, 102 (in B3), 104 (in B4), etc, and in Sheet1 in col.A starting with A2, mixed text with numbes with no logical place text like: abc813bnm 12mn (in A2), fgh 81lkj 45ol (in A3), ert1042hji (in A4), and so on. I need to search each number from col.B/Sheet2 in col.A/Sheet1 and write in is an exact match on the same row in col.Q let's say. he exact match of first no.81 is in A3 (fgh 81lkj 45ol), but not in A2 (abc813bnm 12mn) where it is inside of 813 string. In my code 81 (and not only) it is "found" and in the cell with 81 and in a cell with 813, and I do not want that:



    Sub SearchLCL()



    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.EnableEvents = False

    Dim LCL1 As String
    Dim LCL2 As String
    'Dim answer As String
    Dim c As Range
    Dim counter As Long
    Dim totalLCL1 As Long
    Dim totalLCL2 As Long

    counter = 2

    'Sheets("MailElibLCL").Select 'Sheet2
    'Sheets("lucrari 2017").Select 'Sheet1

    totalLCL2 = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    totalLCL1 = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row

    'totalLCL2 = N
    'totalLCL1 = N3

    For I = 2 To totalLCL2
    'answer = Worksheets("hedis1").Range("h" & counter).Value
    LCL2 = Worksheets("Sheet1").Range("A" & counter).Value
    'LCL2 = "=MID(Worksheets.Sheet1.Range(""A"" & counter),SEARCH(LCL1,Worksheets.Sheet1.Range(""A"" & counter)),LEN(LCL1))"
    k = "Q" & counter
    For j = 2 To totalLCL1
    LCL1 = Worksheets("Sheet2").Range("B" & j).Value

    If InStr(1, LCL2, LCL1, vbTextCompare) > 0 Then
    Debug.Print LCL1

    'If LCL1 = LCL2 Then
    'If answer = "Yes" Then
    For Each c In Worksheets("Sheet1").Range(k)

    'c.Value = Mid(LCL2, Search(LCL1, LCL2), Len(LCL1))
    'c.Formula = "=MID(LCL2,INSTR(LCL1,LCL2),LEN(LCL1))"
    'c.EntireRow.Interior.Color = 6 ' Change the number to match the desired color.
    c.Value = LCL1 '& vbLf & Date 'Now (si ora minute secunde)
    'c.Interior.Color = 5296210 ' Change the number to match the desired color.

    Next c
    'End If
    'End If
    End If
    Next j
    counter = counter + 1
    Next I


    'Else
    'Call ScrieMailElib
    'End If



    On Error GoTo 0



    Application.EnableEvents = True
    Application.DisplayStatusBar = True
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic


    End Sub



    Thank you.










    share|improve this question



























      1












      1








      1








      I have only numbers in Sheet2 in col.B starting with B2: 81, 102 (in B3), 104 (in B4), etc, and in Sheet1 in col.A starting with A2, mixed text with numbes with no logical place text like: abc813bnm 12mn (in A2), fgh 81lkj 45ol (in A3), ert1042hji (in A4), and so on. I need to search each number from col.B/Sheet2 in col.A/Sheet1 and write in is an exact match on the same row in col.Q let's say. he exact match of first no.81 is in A3 (fgh 81lkj 45ol), but not in A2 (abc813bnm 12mn) where it is inside of 813 string. In my code 81 (and not only) it is "found" and in the cell with 81 and in a cell with 813, and I do not want that:



      Sub SearchLCL()



      Application.Calculation = xlCalculationManual
      Application.ScreenUpdating = False
      Application.DisplayStatusBar = False
      Application.EnableEvents = False

      Dim LCL1 As String
      Dim LCL2 As String
      'Dim answer As String
      Dim c As Range
      Dim counter As Long
      Dim totalLCL1 As Long
      Dim totalLCL2 As Long

      counter = 2

      'Sheets("MailElibLCL").Select 'Sheet2
      'Sheets("lucrari 2017").Select 'Sheet1

      totalLCL2 = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
      totalLCL1 = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row

      'totalLCL2 = N
      'totalLCL1 = N3

      For I = 2 To totalLCL2
      'answer = Worksheets("hedis1").Range("h" & counter).Value
      LCL2 = Worksheets("Sheet1").Range("A" & counter).Value
      'LCL2 = "=MID(Worksheets.Sheet1.Range(""A"" & counter),SEARCH(LCL1,Worksheets.Sheet1.Range(""A"" & counter)),LEN(LCL1))"
      k = "Q" & counter
      For j = 2 To totalLCL1
      LCL1 = Worksheets("Sheet2").Range("B" & j).Value

      If InStr(1, LCL2, LCL1, vbTextCompare) > 0 Then
      Debug.Print LCL1

      'If LCL1 = LCL2 Then
      'If answer = "Yes" Then
      For Each c In Worksheets("Sheet1").Range(k)

      'c.Value = Mid(LCL2, Search(LCL1, LCL2), Len(LCL1))
      'c.Formula = "=MID(LCL2,INSTR(LCL1,LCL2),LEN(LCL1))"
      'c.EntireRow.Interior.Color = 6 ' Change the number to match the desired color.
      c.Value = LCL1 '& vbLf & Date 'Now (si ora minute secunde)
      'c.Interior.Color = 5296210 ' Change the number to match the desired color.

      Next c
      'End If
      'End If
      End If
      Next j
      counter = counter + 1
      Next I


      'Else
      'Call ScrieMailElib
      'End If



      On Error GoTo 0



      Application.EnableEvents = True
      Application.DisplayStatusBar = True
      Application.ScreenUpdating = True
      Application.Calculation = xlCalculationAutomatic


      End Sub



      Thank you.










      share|improve this question
















      I have only numbers in Sheet2 in col.B starting with B2: 81, 102 (in B3), 104 (in B4), etc, and in Sheet1 in col.A starting with A2, mixed text with numbes with no logical place text like: abc813bnm 12mn (in A2), fgh 81lkj 45ol (in A3), ert1042hji (in A4), and so on. I need to search each number from col.B/Sheet2 in col.A/Sheet1 and write in is an exact match on the same row in col.Q let's say. he exact match of first no.81 is in A3 (fgh 81lkj 45ol), but not in A2 (abc813bnm 12mn) where it is inside of 813 string. In my code 81 (and not only) it is "found" and in the cell with 81 and in a cell with 813, and I do not want that:



      Sub SearchLCL()



      Application.Calculation = xlCalculationManual
      Application.ScreenUpdating = False
      Application.DisplayStatusBar = False
      Application.EnableEvents = False

      Dim LCL1 As String
      Dim LCL2 As String
      'Dim answer As String
      Dim c As Range
      Dim counter As Long
      Dim totalLCL1 As Long
      Dim totalLCL2 As Long

      counter = 2

      'Sheets("MailElibLCL").Select 'Sheet2
      'Sheets("lucrari 2017").Select 'Sheet1

      totalLCL2 = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
      totalLCL1 = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row

      'totalLCL2 = N
      'totalLCL1 = N3

      For I = 2 To totalLCL2
      'answer = Worksheets("hedis1").Range("h" & counter).Value
      LCL2 = Worksheets("Sheet1").Range("A" & counter).Value
      'LCL2 = "=MID(Worksheets.Sheet1.Range(""A"" & counter),SEARCH(LCL1,Worksheets.Sheet1.Range(""A"" & counter)),LEN(LCL1))"
      k = "Q" & counter
      For j = 2 To totalLCL1
      LCL1 = Worksheets("Sheet2").Range("B" & j).Value

      If InStr(1, LCL2, LCL1, vbTextCompare) > 0 Then
      Debug.Print LCL1

      'If LCL1 = LCL2 Then
      'If answer = "Yes" Then
      For Each c In Worksheets("Sheet1").Range(k)

      'c.Value = Mid(LCL2, Search(LCL1, LCL2), Len(LCL1))
      'c.Formula = "=MID(LCL2,INSTR(LCL1,LCL2),LEN(LCL1))"
      'c.EntireRow.Interior.Color = 6 ' Change the number to match the desired color.
      c.Value = LCL1 '& vbLf & Date 'Now (si ora minute secunde)
      'c.Interior.Color = 5296210 ' Change the number to match the desired color.

      Next c
      'End If
      'End If
      End If
      Next j
      counter = counter + 1
      Next I


      'Else
      'Call ScrieMailElib
      'End If



      On Error GoTo 0



      Application.EnableEvents = True
      Application.DisplayStatusBar = True
      Application.ScreenUpdating = True
      Application.Calculation = xlCalculationAutomatic


      End Sub



      Thank you.







      excel vba excel-vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 4 at 15:28









      J.schmidt

      661120




      661120










      asked Jan 4 at 12:01









      ValentinValentin

      62




      62
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I think you can just use a formula, this example is checking for 30 in abc30ded435wdfq345 for example



          =IF(ISERROR(SEARCH(30,J16,1)),"No Match","Match")



          Not sure if I fully understand your problem.






          share|improve this answer































            0














            Perhaps you can work this into your code. It uses regular expressions. It's a surprisingly lengthy pattern to find a simple number.



            This just looks for the number 81.



            Sub x()

            Dim oRgx As Object, rCell As Range

            Set oRgx = CreateObject("VBScript.RegExp")

            With oRgx
            .Global = True
            .Pattern = "([^0-9]|^)81([^0-9]|$)"
            For Each rCell In ActiveSheet.UsedRange
            If .Test(rCell) Then MsgBox rCell.Address
            Next rCell
            End With

            End Sub


            enter image description here






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038602%2ffind-an-exact-match-of-a-number-into-a-text-string-with-random-letters-and-numbe%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I think you can just use a formula, this example is checking for 30 in abc30ded435wdfq345 for example



              =IF(ISERROR(SEARCH(30,J16,1)),"No Match","Match")



              Not sure if I fully understand your problem.






              share|improve this answer




























                0














                I think you can just use a formula, this example is checking for 30 in abc30ded435wdfq345 for example



                =IF(ISERROR(SEARCH(30,J16,1)),"No Match","Match")



                Not sure if I fully understand your problem.






                share|improve this answer


























                  0












                  0








                  0







                  I think you can just use a formula, this example is checking for 30 in abc30ded435wdfq345 for example



                  =IF(ISERROR(SEARCH(30,J16,1)),"No Match","Match")



                  Not sure if I fully understand your problem.






                  share|improve this answer













                  I think you can just use a formula, this example is checking for 30 in abc30ded435wdfq345 for example



                  =IF(ISERROR(SEARCH(30,J16,1)),"No Match","Match")



                  Not sure if I fully understand your problem.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 4 at 12:08









                  Nathan_SavNathan_Sav

                  6,4511619




                  6,4511619

























                      0














                      Perhaps you can work this into your code. It uses regular expressions. It's a surprisingly lengthy pattern to find a simple number.



                      This just looks for the number 81.



                      Sub x()

                      Dim oRgx As Object, rCell As Range

                      Set oRgx = CreateObject("VBScript.RegExp")

                      With oRgx
                      .Global = True
                      .Pattern = "([^0-9]|^)81([^0-9]|$)"
                      For Each rCell In ActiveSheet.UsedRange
                      If .Test(rCell) Then MsgBox rCell.Address
                      Next rCell
                      End With

                      End Sub


                      enter image description here






                      share|improve this answer




























                        0














                        Perhaps you can work this into your code. It uses regular expressions. It's a surprisingly lengthy pattern to find a simple number.



                        This just looks for the number 81.



                        Sub x()

                        Dim oRgx As Object, rCell As Range

                        Set oRgx = CreateObject("VBScript.RegExp")

                        With oRgx
                        .Global = True
                        .Pattern = "([^0-9]|^)81([^0-9]|$)"
                        For Each rCell In ActiveSheet.UsedRange
                        If .Test(rCell) Then MsgBox rCell.Address
                        Next rCell
                        End With

                        End Sub


                        enter image description here






                        share|improve this answer


























                          0












                          0








                          0







                          Perhaps you can work this into your code. It uses regular expressions. It's a surprisingly lengthy pattern to find a simple number.



                          This just looks for the number 81.



                          Sub x()

                          Dim oRgx As Object, rCell As Range

                          Set oRgx = CreateObject("VBScript.RegExp")

                          With oRgx
                          .Global = True
                          .Pattern = "([^0-9]|^)81([^0-9]|$)"
                          For Each rCell In ActiveSheet.UsedRange
                          If .Test(rCell) Then MsgBox rCell.Address
                          Next rCell
                          End With

                          End Sub


                          enter image description here






                          share|improve this answer













                          Perhaps you can work this into your code. It uses regular expressions. It's a surprisingly lengthy pattern to find a simple number.



                          This just looks for the number 81.



                          Sub x()

                          Dim oRgx As Object, rCell As Range

                          Set oRgx = CreateObject("VBScript.RegExp")

                          With oRgx
                          .Global = True
                          .Pattern = "([^0-9]|^)81([^0-9]|$)"
                          For Each rCell In ActiveSheet.UsedRange
                          If .Test(rCell) Then MsgBox rCell.Address
                          Next rCell
                          End With

                          End Sub


                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 4 at 12:20









                          SJRSJR

                          13.7k31219




                          13.7k31219






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038602%2ffind-an-exact-match-of-a-number-into-a-text-string-with-random-letters-and-numbe%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Mossoró

                              Error while reading .h5 file using the rhdf5 package in R

                              Pushsharp Apns notification error: 'InvalidToken'