0 votes
in VBA by Beginner (15 points)
How to loop "A" column that contains a text in "B" column till last row, if text matches give a comment in "C"column.

3 Answers

+2 votes
by Skilled (265 points)
selected by
 
Best answer

Okay, I think I understand what you're asking.

Option Explicit
Public Sub LoopAndLook()

' Added a second loop to Ryan's version
' Added a different test, using Application.Evaluate
' Displays CASE-INSENSITVE results in column C
' This means Excel = excel

Dim lastrowA As Long
Dim lastrowB As Long
Dim i As Long
Dim j As Long

lastrowA = Range("A" & Rows.Count).End(xlUp).Row
lastrowB = Range("B" & Rows.Count).End(xlUp).Row

For i = 1 To lastrowA
    Range("C" & i) = ""
    For j = 1 To lastrowB
        If Application.Evaluate("=IFERROR(FIND(LOWER(B" & j & "),LOWER(A" & i & ")),0)") Then
            Range("C" & i) = Range("C" & i) & "/ found: " & Range("B" & j)
        End If
    Next j
Next i
End Sub
by Beginner (15 points)
Thank you !
It's working fine now ! :)
by Skilled (265 points)
You're welcome! Glad I could help.
+2 votes
by Super Expert (1.9k points)

This macro will loop through all the cells in column A and if the value in that cell matches any value in column B, it will add text to column C stating the value in that row in column A matches a value in column B:

Sub LoopAndLook()
Dim lastrowA As Long
Dim lastrowB As Long
Dim i As Long

lastrowA = Range("A" & Rows.Count).End(xlUp).Row
lastrowB = Range("B" & Rows.Count).End(xlUp).Row

For i = 1 To lastrowA
    If Application.CountIf(Range("B1:B" & lastrowB), Range("A" & i)) <> 0 Then
        Range("C" & i) = "Value in A" & i & " exists in column B."
    End If
Next i
End Sub

 

by Beginner (15 points)
Hi,
Thanks for the above Code.
But it's not working completely.

I need to loop "A" Column multiple times with the text contains in "B" Column.

Example: in B column i have "excel", "Term" with this text loop in "A" column ex: Excelword, excelworld, excelpoint, terms, terminology, termination... etc.. if text contains "A" column matches with "B" column text then. put a comment in "C" Column.
0 votes
by Skilled (401 points)

You can simply use simple formula using MATCH

So in C1 put this formula and drag

=IFERROR(MATCH(A1,B:B,0),"")

 

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and/or answers. Users that ask great questions, may be given complimentary gift cards or training material.

Getting Started
Register

So, why don't you join us? It really is a neat way to reward the most dedicated members in our VBA and Python community.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...