+ Reply to Thread
Results 1 to 4 of 4

VBA code to identify the cell number in a column which contains a specific text

Hybrid View

  1. #1
    Registered User
    Join Date
    04-28-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    81

    VBA code to identify the cell number in a column which contains a specific text

    In Column A if cell 36 has "2015 Stores" then i need a code to identify this cell number.

    This can be dynamic and the text can be present in any cell.

    Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: VBA code to identify the cell number in a column which contains a specific text

    This will do if it's in column A & 2015 Stores is in B1
    =IFERROR(ADDRESS(ROW(INDEX(A:A,MATCH(B1,A:A,0))),1),"?")

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: VBA code to identify the cell number in a column which contains a specific text

    Try something like this...
    Sub FindCellNumber()
    Dim cell As Range
    Dim FindValue As String
    FindValue = "2015 Stores"
    Set cell = Range("A:A").Find(FindValue)
    If Not cell Is Nothing Then
        MsgBox cell.Address(0, 0)
    Else
        MsgBox FindValue & " is not found in Column A."
    End If
    End Sub
    You may change the FindValue in the red line if you are looking for some other text in col. A. The above code will give you the address of the cell in col. A which contains 2015 Stores in it.
    Moreover if you are interested in knowing the row number, you may change the message box to this...
    MsgBox cell.Row
    Does this help?
    Last edited by sktneer; 12-09-2014 at 03:11 AM.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: VBA code to identify the cell number in a column which contains a specific text

    It just dawned on me you asked for VBA code. I see sktneer has already given one solution
    Here's another. It'll find it anywhere on worksheet 1
    Option Explicit
    
    Sub FindAddress()
    Dim Ws As Worksheet
    Dim Col As Long
    Dim rRow As Long
    Dim String2Find As String
    Set Ws = ThisWorkbook.Sheets(1)
    String2Find = "2015 Stores"
    
            On Error Resume Next
                rRow = Ws.Rows().Find(What:=String2Find, LookIn:=xlValues, _
                            LookAt:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlPrevious, _
                            MatchCase:=False, SearchFormat:=False).Row
                            
                Col = Ws.Columns().Find(What:=String2Find, LookIn:=xlValues, _
                        LookAt:=xlPart, SearchOrder:=xlByColumns, searchdirection:=xlPrevious, _
                        MatchCase:=False, SearchFormat:=False).Column
            On Error GoTo 0
            
    If Not rRow = 0 Or Not Col = 0 Then
    MsgBox String2Find & " Is In " & Ws.Cells(rRow, Col).Address
    Else
    MsgBox String2Find & " Not Found"
    End If
    
    End Sub

+ 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] Macro code to show only the rows with specific cell text in a particular column
    By Itachi1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2013, 01:33 PM
  2. How to find a cell from a range and identify its column number
    By JamesGoulding85 in forum Excel General
    Replies: 2
    Last Post: 06-06-2013, 08:29 AM
  3. Replies: 1
    Last Post: 02-08-2013, 12:24 PM
  4. Replies: 1
    Last Post: 05-09-2012, 01:30 PM
  5. search column of text cellto identify those cells with specific w
    By Ross Headifen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-08-2006, 09:55 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