• Ask a Question
150
Insert Image Size must be less than < 5MB.
    Ask a Question
    Cancel
    150
    More answer You can create 5 answer(s).
      Ask a Poll
      Cancel
      Participant

      Comparing two columns and get the result

      Hi

      I have two types of data in two separate columns.One column have some results in it. I want to compare some specific words which are in column 1 with column 2 and want to get that result in another column. I am giving one example of it.

      Column1                              Column2                                                             Column3

      Senior secured loans     percentage of senior secured loans    SSL

      I want to get the result “SSL” for all those data in the column 2 which consists senior secured.

      Thanks

      Asked by tanaymalik on September 15, 2017 in VBA: Macros.
      2 Answers
      Keymaster

      Hello,

       

      Here is the VBA code to match a string and print the result.

       

      Sub sbMatchStringInColumn()
      lRow = 500 'This is your last row with data in the sheet/specific column
      For iCntr = 1 To lRow
      'This will check if column B values contains a sting and print in Column C
      If InStr(1, Range("B" & iCntr), "senior secured") Then Range("C" & iCntr) = "SSL"
      'If you want to check in both A & B Columns see the below statement
      'If (InStr(1, Range("A" & iCntr), "senior secured") And InStr(1, Range("B" & iCntr), "senior secured")) Then Range("C" & iCntr) = "SSL"
      Next iCntr
      End Sub
      

      Thanks!

      Answered by PNRao on September 15, 2017..
      Expert

      Thanks a lot PNRao for solution

      I think it will be better to upload sample of your workbook with some more data and put some of the expected output

      Would you like the results to have the initials of column A if found in column B?

      Answered by YasserKhalil on January 29, 2018..