LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default checking for empty rows before copying?

Hi,
The below code copies records that has a non blank cells in column C from
Sheet1 to Sheet2. So far so good. But it re-writes on top of the old records
on Sheet2. How can I modify it so that it'll check for empty rows on Sheet2
and then copy data from Sheet1 to Sheet2?.
TIA

'---------------------------------
Sub Copy_them()
Dim rng As Range, cell As Range, col As Long
Dim rw As Long, rng2 As Range
col = 3
rw = 2
With Worksheets("sheet1")
Set rng = .Range(.Cells(2, col), .Cells(Rows.Count, col).End(xlUp))
End With
For Each cell In rng
If LCase(cell.Value) < "" Then
cell.EntireRow.Copy Destination:=Worksheets("sheet2") _
.Cells(rw, 1)
rw = rw + 1
If rng2 Is Nothing Then
Set rng2 = cell
Else
Set rng2 = Union(rng2, cell)
End If
End If
Next
If Not rng2 Is Nothing Then
rng2.EntireRow.Delete
End If
End Sub
'-------------------------------



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for empty cells in a range Chris Strug Excel Programming 8 June 21st 05 12:07 AM
Checking for empty cells in a range Chris Strug Excel Programming 3 June 20th 05 03:11 PM
Checking for empty cells in a range Chris Strug Excel Worksheet Functions 2 June 20th 05 10:33 AM
Checking if an Excel file is empty? Kintan Excel Programming 0 November 11th 04 03:24 AM
Skipping empty rows when copying a formula down a column Rachel Jones Excel Programming 1 July 31st 03 03:55 AM


All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"