+ Reply to Thread
Results 1 to 2 of 2

Selecting a single row range

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Posts
    164

    Selecting a single row range

    I have some code to find a value in a worksheet:

    Please Login or Register  to view this content.
    I need to be able, once found, to offset by 4 rows to the right and then select the next 12 rows and copy.

    basically 4 cells to the right of 'HTD Total' is a row of 12 cells I need to copy.

    what is the syntax for the selecting this range?

    thanks in advance,

  2. #2
    Jim Thomlinson
    Guest

    RE: Selecting a single row range

    Your code needs to handle the case where what you are looking for is not
    found. Here is some code for you to try...

    Sub Test()
    Dim rngFound As Range
    Dim rngCopyArea As Range
    Dim wks As Worksheet

    Set wks = ActiveSheet
    Set rngFound = wks.Cells.Find("HTD Total")

    If rngFound Is Nothing Then
    MsgBox "HTD Total was not found"
    Else
    Set rngCopyArea = wks.Range(rngFound.Offset(0, 4),
    rngFound.Offset(0, 16))
    rngCopyArea.Copy Sheets("Sheet2").Range("A1")
    End If
    Set wks = Nothing
    Set rngFound = Nothing
    Set rngCopyArea = Nothing
    End Sub

    --
    HTH...

    Jim Thomlinson


    "matpj" wrote:

    >
    > I have some code to find a value in a worksheet:
    >
    >
    > Code:
    > --------------------
    >
    > Cells.Find(What:="HTD Total", After:=ActiveCell, LookIn:=xlFormulas, _
    > LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    > MatchCase:=False).Activate
    > --------------------
    >
    >
    > I need to be able, once found, to offset by 4 rows to the right and
    > then select the next 12 rows and copy.
    >
    > basically 4 cells to the right of 'HTD Total' is a row of 12 cells I
    > need to copy.
    >
    > what is the syntax for the selecting this range?
    >
    > thanks in advance,
    >
    >
    > --
    > matpj
    > ------------------------------------------------------------------------
    > matpj's Profile: http://www.excelforum.com/member.php...o&userid=21076
    > View this thread: http://www.excelforum.com/showthread...hreadid=481912
    >
    >


+ 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