Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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
'-------------------------------



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default checking for empty rows before copying?

rw = Worksheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1

--

HTH

RP
(remove nothere from the email address if mailing direct)


"J_J" wrote in message
...
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
'-------------------------------





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default checking for empty rows before copying?

Hi Bob,
Thank you for your suggestion. Unfortunately that didn't help. When I
replaced the code with the new def. of rw
run the macro, get 4 records copied to Sheet2, fill in a cell from column C
and run the macro again, it just copied the new item on top of the old
record previously copied from the first run.
What am I doing wrong here?
Sincerely
J_J

"Bob Phillips" wrote in message
...
rw = Worksheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1

--

HTH

RP
(remove nothere from the email address if mailing direct)


"J_J" wrote in message
...
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
'-------------------------------







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default checking for empty rows before copying?

J_J,

Did you put it in the correct place? I meant replace this

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 this

Sub Copy_them()
Dim rng As Range, cell As Range, col As Long
Dim rw As Long, rng2 As Range
col = 3
rw = Worksheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1


--

HTH

RP
(remove nothere from the email address if mailing direct)


"J_J" wrote in message
...
Hi Bob,
Thank you for your suggestion. Unfortunately that didn't help. When I
replaced the code with the new def. of rw
run the macro, get 4 records copied to Sheet2, fill in a cell from column

C
and run the macro again, it just copied the new item on top of the old
record previously copied from the first run.
What am I doing wrong here?
Sincerely
J_J

"Bob Phillips" wrote in message
...
rw = Worksheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1

--

HTH

RP
(remove nothere from the email address if mailing direct)


"J_J" wrote in message
...
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
'-------------------------------









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default checking for empty rows before copying?

Thank you Bob,
I have replaced the wrong statement...
Now it works perfectly well.
J_J


"Bob Phillips" wrote in message
...
J_J,

Did you put it in the correct place? I meant replace this

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 this

Sub Copy_them()
Dim rng As Range, cell As Range, col As Long
Dim rw As Long, rng2 As Range
col = 3
rw = Worksheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1


--

HTH

RP
(remove nothere from the email address if mailing direct)


"J_J" wrote in message
...
Hi Bob,
Thank you for your suggestion. Unfortunately that didn't help. When I
replaced the code with the new def. of rw
run the macro, get 4 records copied to Sheet2, fill in a cell from column

C
and run the macro again, it just copied the new item on top of the old
record previously copied from the first run.
What am I doing wrong here?
Sincerely
J_J

"Bob Phillips" wrote in message
...
rw = Worksheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1

--

HTH

RP
(remove nothere from the email address if mailing direct)


"J_J" wrote in message
...
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
'-------------------------------












Reply
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 04:49 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"