+ Reply to Thread
Results 1 to 4 of 4

Lopp in column to find and select

  1. #1
    al007
    Guest

    Lopp in column to find and select

    Looking for a code which would loop in a column to find and select what
    is in my active cell.

    Eg: Activecell : B5 = "Test"

    B6 & B7 also contains "Test"

    How can I loop in column B to find & select all 3 cells.

    Thxs


  2. #2
    Norman Jones
    Guest

    Re: Lopp in column to find and select

    Hi Al007,

    Try:

    '=============>>
    Public Sub Tester1A()
    Dim rng As Range
    Dim rngFound As Range
    Dim rngOut As Range
    Dim sStr As String
    Dim firstAdd As String

    Set rng = ActiveCell
    sStr = rng.Value

    Set rngFound = rng.EntireColumn.Find _
    (What:=sStr, _
    After:=rng(1), _
    LookIn:=xlValues, _
    LookAt:=xlPart, _
    SearchOrder:=xlByColumns, _
    SearchDirection:=xlNext)

    If Not rngFound Is Nothing Then
    firstAdd = rngFound.Address
    Set rngOut = rngFound
    End If

    Do
    Set rngFound = rng.EntireColumn.FindNext(rngFound)
    If Not rngFound Is Nothing Then
    Set rngOut = Union(rngOut, rngFound)
    End If
    Loop While Not rngFound Is Nothing _
    And rngFound.Address <> firstAdd


    If Not rngOut Is Nothing Then rngOut.Select

    End Sub
    '<<=============

    This is an adaptation of the example code provided by VBA help.


    ---
    Regards,
    Norman


    "al007" <[email protected]> wrote in message
    news:[email protected]...
    > Looking for a code which would loop in a column to find and select what
    > is in my active cell.
    >
    > Eg: Activecell : B5 = "Test"
    >
    > B6 & B7 also contains "Test"
    >
    > How can I loop in column B to find & select all 3 cells.
    >
    > Thxs
    >




  3. #3
    al007
    Guest

    Re: Lopp in column to find and select

    thxs a lot for your help !!


  4. #4
    aspiringlawtechie0615
    Guest

    Re: Lopp in column to find and select


    While i am deciphering the code below, may i know if you also could help
    with my scenario.

    Given: A robust worksheet with almost 10,000 rows.

    Column A could have the same entries.
    ig A1= Apple; A2= Apple
    If this is the case, then the row of A2 must be deleted.

    We are aiming to have a file whose Column A entries are unique from each
    other.


    Please help...
    Thank you for your immediate consideration.

    Happy New Year!


    "Norman Jones" wrote:

    > Hi Al007,
    >
    > Try:
    >
    > '=============>>
    > Public Sub Tester1A()
    > Dim rng As Range
    > Dim rngFound As Range
    > Dim rngOut As Range
    > Dim sStr As String
    > Dim firstAdd As String
    >
    > Set rng = ActiveCell
    > sStr = rng.Value
    >
    > Set rngFound = rng.EntireColumn.Find _
    > (What:=sStr, _
    > After:=rng(1), _
    > LookIn:=xlValues, _
    > LookAt:=xlPart, _
    > SearchOrder:=xlByColumns, _
    > SearchDirection:=xlNext)
    >
    > If Not rngFound Is Nothing Then
    > firstAdd = rngFound.Address
    > Set rngOut = rngFound
    > End If
    >
    > Do
    > Set rngFound = rng.EntireColumn.FindNext(rngFound)
    > If Not rngFound Is Nothing Then
    > Set rngOut = Union(rngOut, rngFound)
    > End If
    > Loop While Not rngFound Is Nothing _
    > And rngFound.Address <> firstAdd
    >
    >
    > If Not rngOut Is Nothing Then rngOut.Select
    >
    > End Sub
    > '<<=============
    >
    > This is an adaptation of the example code provided by VBA help.
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    > "al007" <[email protected]> wrote in message
    > news:[email protected]...
    > > Looking for a code which would loop in a column to find and select what
    > > is in my active cell.
    > >
    > > Eg: Activecell : B5 = "Test"
    > >
    > > B6 & B7 also contains "Test"
    > >
    > > How can I loop in column B to find & select all 3 cells.
    > >
    > > Thxs
    > >

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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