+ Reply to Thread
Results 1 to 2 of 2

remove blank rows and copy new range

Hybrid View

twofootgiant remove blank rows and copy... 04-27-2010, 08:36 AM
Andy Pope Re: remove blank rows and... 04-27-2010, 09:11 AM
  1. #1
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    remove blank rows and copy new range

    Hi Guys.

    I have a range or four columns filled with data. I need to copy only the rows which have a full set of data into a new sheet.
    i.e. If on row 1 there was data in the first three colums but not in the fourth then that row would not be included.
    But if on row 2 there was data in all four cells then that row would be copied to a new sheet.

    The new sheet should be called DESPATCH NOTE.

    Any ideas on how to do this?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: remove blank rows and copy new range

    Sub xx()
        
        Dim rngToCopy As Range
        Dim rngRow As Range
        Dim rngData As Range
        
        Set rngData = Range("A1:D6")
        On Error Resume Next
        For Each rngRow In rngData.Rows
            If rngRow.SpecialCells(xlCellTypeBlanks) Is Nothing Then
                If rngToCopy Is Nothing Then
                    Set rngToCopy = rngRow
                Else
                    Set rngToCopy = Union(rngToCopy, rngRow)
                End If
            End If
        Next
        
        If Not rngToCopy Is Nothing Then
            Worksheets.Add
            ActiveSheet.Name = "DESPATCH NOTE"
            rngToCopy.Copy ActiveSheet.Range("A1")
        End If
        
    End Sub
    Cheers
    Andy
    www.andypope.info

+ 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