+ Reply to Thread
Results 1 to 7 of 7

Thread: Select variable range in the middle of worksheet down to the next blank row

  1. #1
    Registered User
    Join Date
    06-05-2009
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Excel 2003
    Posts
    4

    Select variable range in the middle of worksheet down to the next blank row

    Hi guys, I am sure this is a piece of cake for you, however, I could not find solution for this task.

    My sheet looks as follows:
    lots of data
    lots of data
    blank row
    lots of data (including cell named "real cost")
    blank row
    ...
    'and here comes the table of variable length that I want to copy
    'cell in column H is named "real cost" - so it's the 2nd time from the beginning that cell has such text
    'I want to select area from the H cell "real cost" to cell in the same row in A column and down to the next blank row (without the blank row)

    ....
    lots of data
    blank row
    lots of data
    So basically, I want to select the variable range somewhere in the middle of the sheet from where the 2nd instance of cell named "real cost" is, down to the next blank row (select the area without the blank row), so that I could copy it to another sheet.

    Thanks a lot.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Select variable range in the middle of worksheet down to the next blank row

    Taake a look at the CurrentRegion or UsedRange in the VBA help or attach a workbook.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    06-05-2009
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Select variable range in the middle of worksheet down to the next blank row

    I have attached the xls file (I have deleted the real data).

    For this case, I would select/copy range A449:H505 (the yellow area in my attachment). But this area will change for another case.

    The rule is:
    1. find the 2nd instance of "*Real* Cost (BMC)" in cells from the beginning (it should be in column H)
    2. select area from there to cell in column A (on the same row)
    3. continue with selecting area down until you encounter blank row (this number of filled rows is variable)
    4. select the variable range (without the blank row) and then copy it

    Thanks.
    Attached Files Attached Files
    Last edited by rookie1ja; 06-05-2009 at 06:44 AM.

  4. #4
    Registered User
    Join Date
    06-05-2009
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Select variable range in the middle of worksheet down to the next blank row

    Bump no response resolving my issue.

    Pls could you have a look at my post above - 4 points with what I want to achieve and the xls file is attached in the post as well.

    Thanks.

  5. #5
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Select variable range in the middle of worksheet down to the next blank row

    This code will do what you describe
        Const sFind As String = "*Real* Cost (BMC)"
        Dim rng    As Range
        Dim rSearch As Range
        Dim cl     As Range
        Dim StartRw As Long
        Dim i      As Integer
    
        With ActiveSheet
            Set rSearch = .Columns(8)
            With rSearch
                Set cl = .Find(sFind, LookIn:=xlValues)
                If Not cl Is Nothing Then
                    Do Until i = 2
                        i = i + 1
                        Set cl = .FindNext(cl)
                    Loop
                End If
            End With
            StartRw = cl.Row
            Set rng = .Range(.Cells(StartRw, 1), .Cells(StartRw, 8).End(xlDown))
            rng.Select
        End With
    You don't actually need to select the range to perform an action on it such as copying.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  6. #6
    Registered User
    Join Date
    06-05-2009
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Select variable range in the middle of worksheet down to the next blank row

    royUK, your code is GREAT :-)

    I have just amended it to go to the second instance of "*Real* Cost (BMC)" and select area from that 2nd instance.

       Const sFind As String = "*Real* Cost (BMC)"
       Dim rng    As Range
       Dim rSearch As Range
       Dim cl     As Range
       Dim StartRw As Long
       Dim i      As Integer
    
       With ActiveSheet
           Set rSearch = .Columns(8)
           With rSearch
               Set cl = .Find(sFind, LookIn:=xlValues)
               Set cl = .FindNext(cl)
           End With
           StartRw = cl.Row
           Set rng = .Range(.Cells(StartRw, 1), .Cells(StartRw, 8).End(xlDown))
           rng.Select
       End With
    I like your solution very much - simple and beautiful.

    Thanks a lot.

  7. #7
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Select variable range in the middle of worksheet down to the next blank row

    I'm glad it helped. I'll mark this Thread Solved as you seem satisfied.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0