0 votes
in VBA by Beginner (113 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
ago by Beginner (204 points)
selected ago 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
ago by Beginner (113 points)
Thank you !
It's working fine now ! :)
ago by Beginner (204 points)
You're welcome! Glad I could help.
+2 votes
by Super Expert (1.8k 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 (113 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 (306 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 as your contributions grow. The more points you earn, the better the prizes.

Getting Started
Register
Prizes

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

Top Users Mar 2019
  1. YasserKhalil

    306 Points

  2. ParserMonster

    204 Points

  3. Alberto Semat

    186 Points

  4. danmcg

    127 Points

  5. Abdan

    124 Points


Prizes for March 2019
Terms and Conditions
1st place (1) 1-year MyExcelOnline Academy Membership
(2) My First Add-in Dev Pack & Course
(3) AutoMacro: VBA Code Generator (Developer)
(4) VBA Cheat Sheet Bundle
(5) $35 Amazon Gift Card
2nd place (1) My First Add-in Dev Pack & Course
(2) 101 Most Popular Excel Formulas E-Book
(3) VBA Cheat Sheet Bundle
(4) $25 Amazon Gift Card
3rd place (1) Mouse to Macro
(2) VBA Cheat Sheet Bundle
(3) $15 Amazon Gift Card
...