+ Reply to Thread
Results 1 to 3 of 3

Code to search for text in rows

  1. #1
    Registered User
    Join Date
    03-28-2017
    Location
    Stuttgart
    MS-Off Ver
    10
    Posts
    0

    Code to search for text in rows

    Hello guys,

    I am fairly new to VBA.
    Thank you for providing a Forum to share ideas.

    Regards
    RJuma
    Last edited by RJuma; 03-28-2017 at 09:01 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello RJuma,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    03-28-2017
    Location
    Stuttgart
    MS-Off Ver
    10
    Posts
    0

    Re: Code to search for text in rows

    I am searching for text in rows of column B and want to assing values in corresponding rows in column D if the text is found. For instance, if my search criteria is "House", then I want to assign rows in column D the value "Equal match" if the text equals the row value and assing the value "Text found" if the search criteria exists in row for exaple if cell value is "The big House". I have used the below code but it classifies every rows as an "Equal match". Please help . Thanks!!

    strSearch = "House"
    For k = 1 To lrow
    With ws
    If Cells(k, 2).Value Like "*" & strSearch & "*" Then
    ' If Not Cells(k, 2).Value Is Nothing Then
    For j = 1 To Len(Cells(k, 2).Value)
    sPos = InStr(i, Cells(k, 2).Value, strSearch)
    sLen = Len(strSearch)
    If (sPos <> 0) Then
    Cells(k, 4).Value = "Text found"
    Cells(k, 2).EntireRow.Interior.ColorIndex = 27
    r = sPos + Len(strSearch) - 1
    End If
    Next j
    ' End If
    ElseIf Cells(k, 2).Value = strSearch Then
    Cells(k, 4).Value = "Equal match"
    Else
    End If
    End With
    Next k

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Code to search Excel and return results even if part of search text is present
    By Taoyuan00 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2016, 09:20 AM
  2. [SOLVED] VBA Code: Search column for text match, if found add text into row
    By markpem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2014, 08:00 AM
  3. VBA Code - Search text & search number & search qty and result - Urgent Please
    By naresh73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2014, 10:51 AM
  4. Code/Solution To Search All Text in a Cell and Pull UniqueID Corresponding to the Text
    By brandnew22 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-06-2013, 10:56 AM
  5. Replies: 3
    Last Post: 01-09-2013, 07:55 PM
  6. Add rows and search/copy/paste text into added rows
    By HelenW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2010, 04:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1