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

Participant Asked 7 hours ago in VBA: Macros.
Add Comment
1 Answer(s)

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!

Keymaster Answered 38 mins ago.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.