+ Reply to Thread
Results 1 to 6 of 6

IsEmpty

Hybrid View

Determined IsEmpty 02-05-2007, 02:12 PM
Leith Ross Hello Determined, You were... 02-05-2007, 02:27 PM
Determined This is still capturing all... 02-05-2007, 04:57 PM
Leith Ross Hello Determined, Sorry, I... 02-05-2007, 05:08 PM
Determined I am looking for an entire... 02-05-2007, 05:16 PM
Leith Ross Hello Determined, This... 02-05-2007, 07:44 PM
  1. #1
    Registered User
    Join Date
    02-04-2007
    Posts
    15

    IsEmpty

    Please Help!
    Can I select a group of rows starting with a named cell and then selecting all rows until a row is empty?

    I think it goes somthing like this...

     
    Worksheets("Sheet1").Range("Input1").Select
    r = ActiveCell.Row
    lr = ActiveSheet.UsedRange.Rows.Count
    Rows(r & ":" & lr).Select
    .....until r IsEmpty

    Selection.Copy
    Last edited by VBA Noob; 02-05-2007 at 02:28 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Determined,

    You were really close...

    Worksheets("Sheet1").Range("Input1").Select
    r = ActiveCell.Row
    lr = ActiveSheet.UsedRange.Cells(Rows.Count, "A").End(xlUP).Row
    Rows(r & ":" & lr).Select
    Selection.Copy
    There is a possible problem. In this code I used column "A" to find the last row. Each column may not have the same number of non blank rows. You will need to select the column that will always have the most rows filled.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    02-04-2007
    Posts
    15
    This is still capturing all rows that have data on my spreadsheet even though there is an empty row between the sets of data.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Determined,

    Sorry, I misunderstood your post. Will you be looking for an entire empty row or just an empty cell in a specific column? Let me know, I'll rewrite the macro.

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    02-04-2007
    Posts
    15

    Smile

    I am looking for an entire empty row. Thank you for your help.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Determined,

    This macro will select the ActiveCell to the last column in the UsedRange down to the row above the first empty row found. Checks are made to ensure the ActiveCell is not in a blank row or outside the UsedRange (Data area).

    Sub SelectRows()
      
      Dim SearchRng As Range
      
       StartRow = ActiveCell.Row
       StartCol = ActiveCell.Column
       ColCount = ActiveSheet.UsedRange.Columns.Count
       FirstCol = ActiveSheet.UsedRange.Column
       
         If Intersect(ActiveCell, ActiveSheet.UsedRange) Is Nothing Then
            MsgBox "Your selection is outside the data."
            Exit Sub
         End If
         
         With ActiveSheet
           Set SearchRng = .Range(Cells(StartRow, FirstCol), Cells(.UsedRange.Rows.Count, ColCount))
         End With
          
         For Each CurRow In SearchRng.Rows
           Set TestRow = CurRow.SpecialCells(xlCellTypeBlanks)
             If TestRow.Columns.Count = ColCount Then
                If Not Intersect(ActiveCell, TestRow) Is Nothing Then
                   MsgBox "You have selected an empty row."
                   Exit Sub
                End If
                LastRow = CurRow.Row - 1
                ActiveSheet.Range(Cells(StartRow, StartCol), Cells(LastRow, ColCount)).Select
                Exit Sub
             End If
         Next CurRow
           
    End Sub
    Sincerely,
    Leith Ross

+ 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