+ Reply to Thread
Results 1 to 3 of 3

Define a range of cells in VBA

  1. #1
    Noemi
    Guest

    Define a range of cells in VBA

    Hi
    I have about 20 cells running across which contains data.

    What I would like to do is define the range (ie E12:AI12) in VBA so I can do
    a check to see if any of those cells in the range contain a specific word.

    Thanks
    Noemi

  2. #2
    R.VENKATARAMAN
    Guest

    Re: Define a range of cells in VBA

    dim myrange as range
    set myrange=range("e12:a112")

    now you can use <myrange> as range
    for e.g
    myrange.select

    ==================

    "Noemi" <[email protected]> wrote in message
    news:[email protected]...
    > Hi
    > I have about 20 cells running across which contains data.
    >
    > What I would like to do is define the range (ie E12:AI12) in VBA so I can

    do
    > a check to see if any of those cells in the range contain a specific word.
    >
    > Thanks
    > Noemi




  3. #3
    Norman Jones
    Guest

    Re: Define a range of cells in VBA

    Hi Noemi,

    To find each occurrence, try something like:

    '=============>>
    Sub Tester()
    Dim rng As Range
    Dim rCell As Range
    Const sStr As String = "fred" '<<==== CHANGE

    Set rng = Range("E12:AI12")

    For Each rCell In rng.Cells
    If Not IsEmpty(rCell.Value) Then
    If InStr(1, rCell.Value, sStr, vbTextCompare) Then
    'Do something e.g:
    MsgBox sStr & " found at " & rCell.Address(0, 0)
    Else
    'Do something else, or do nothing!
    End If
    End If
    Next

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

    ---
    Regards,
    Norman



    "Noemi" <[email protected]> wrote in message
    news:[email protected]...
    > Hi
    > I have about 20 cells running across which contains data.
    >
    > What I would like to do is define the range (ie E12:AI12) in VBA so I can
    > do
    > a check to see if any of those cells in the range contain a specific word.
    >
    > Thanks
    > Noemi




+ 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