Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Copy rows then delete them

Hello,

Using Excel XP

Assistance in the following matter will be greatly
appreciated.

I have 2 workbooks, both of which are opened, named
Source.xls and Dest.xls. Each workbook consists of one
sheet, named say Sheet1.

Source.xls has data starting in row 7, columns A:K.
Column D has dates (Excel formatted) or blanks. The first
objective is to scan column D in Source.xls for dates
older than 10 days from today, and if found, copy the
entire row to Dest.xls, starting in row 7 downward. The
second objective is to then delete the copied row from
Source.xls.

The following macro from Mr. JE McGinpsey is brilliant in
finding the relevant rows and deleting them, but I need
to copy the rows to Dest.xls first (the macro has been
amended to exclude blanks in column D)

Sub DeleteOldRows()
Dim cell As Range
Dim delRange As Range
Dim TenDaysAgo As Double

TwoDaysAgo = Date - 10
For Each cell In Range("D7:D" & Range("D" & _
Rows.Count).End(xlUp).Row)
If cell.Value < TenDaysAgo And cell.Value < "" Then
If delRange Is Nothing Then
Set delRange = cell
Else
Set delRange = Union(delRange, cell)
End If
End If
Next cell
If Not delRange Is Nothing Then delRange.EntireRow.Delete
End Sub

I have got myself into a major mess with various attempts
to amend the macro by including code such as:
Set wk1 = Workbooks("Dest.xls")
Set rng1 = wk1.Worksheets("Sheet1").Range("A7:A" & Range
("A" & Rows.Count).End(xlUp).Row)

If Not delRange Is Nothing Then delRange.EntireRow.Copy
rng1

The additional code is not looping properly in Dest.xls.
TIA

Richard

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Copy rows then delete them

Hi,

Maybe this works, but I m not sure...You may have to ordonnate your row in dest...good luck lol
Benjamin


Sub DeleteOldRows()
Dim cell As Range
Dim delRange As Range
Dim TenDaysAgo As Double


x=0
TwoDaysAgo = Date - 10
For Each cell In Range("D7:D" & Range("D" & _
Rows.Count).End(xlUp).Row)
If cell.Value < TenDaysAgo And cell.Value < "" Then
x=x+1

windows("Dest").activate

If delRange Is Nothing Then
Set delRange = cell
Else
Set delRange = Union(delRange, cell)
End If
End If
Next cell
If Not delRange Is Nothing Then delRange.EntireRow.copy
windows("dest").activate
Range("A7").select
activesheet.paste

windows("source").activate
If Not delRange Is Nothing Then delRange.EntireRow.Delete
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Copy rows then delete them

Ben,

Thank you for your time and effort but nothing is being
pasted to Dest.xls. In addition, the rows in Source.xls
are not being deleted.

Regards,

Richard

-----Original Message-----
Hi,

Maybe this works, but I m not sure...You may have to

ordonnate your row in dest...good luck lol
Benjamin


Sub DeleteOldRows()
Dim cell As Range
Dim delRange As Range
Dim TenDaysAgo As Double


x=0
TwoDaysAgo = Date - 10
For Each cell In Range("D7:D" & Range("D" & _
Rows.Count).End(xlUp).Row)
If cell.Value < TenDaysAgo And cell.Value < "" Then
x=x+1

windows("Dest").activate

If delRange Is Nothing Then
Set delRange = cell
Else
Set delRange = Union(delRange, cell)
End If
End If
Next cell
If Not delRange Is Nothing Then delRange.EntireRow.copy
windows("dest").activate
Range("A7").select
activesheet.paste

windows("source").activate
If Not delRange Is Nothing Then delRange.EntireRow.Delete
End Sub

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Copy rows then delete them

Here is an example of copy/delete that you can modify to suit. If you wanted
to copy without deleting just substitute copy for cut.

Worksheets("Sheet1").Range("A:ZZ").Cut _
Worksheets("Sheet2").Range("A:ZZ")


--
Don Guillett
SalesAid Software

"Richard" wrote in message
...
Hello,

Using Excel XP

Assistance in the following matter will be greatly
appreciated.

I have 2 workbooks, both of which are opened, named
Source.xls and Dest.xls. Each workbook consists of one
sheet, named say Sheet1.

Source.xls has data starting in row 7, columns A:K.
Column D has dates (Excel formatted) or blanks. The first
objective is to scan column D in Source.xls for dates
older than 10 days from today, and if found, copy the
entire row to Dest.xls, starting in row 7 downward. The
second objective is to then delete the copied row from
Source.xls.

The following macro from Mr. JE McGinpsey is brilliant in
finding the relevant rows and deleting them, but I need
to copy the rows to Dest.xls first (the macro has been
amended to exclude blanks in column D)

Sub DeleteOldRows()
Dim cell As Range
Dim delRange As Range
Dim TenDaysAgo As Double

TwoDaysAgo = Date - 10
For Each cell In Range("D7:D" & Range("D" & _
Rows.Count).End(xlUp).Row)
If cell.Value < TenDaysAgo And cell.Value < "" Then
If delRange Is Nothing Then
Set delRange = cell
Else
Set delRange = Union(delRange, cell)
End If
End If
Next cell
If Not delRange Is Nothing Then delRange.EntireRow.Delete
End Sub

I have got myself into a major mess with various attempts
to amend the macro by including code such as:
Set wk1 = Workbooks("Dest.xls")
Set rng1 = wk1.Worksheets("Sheet1").Range("A7:A" & Range
("A" & Rows.Count).End(xlUp).Row)

If Not delRange Is Nothing Then delRange.EntireRow.Copy
rng1

The additional code is not looping properly in Dest.xls.
TIA

Richard



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
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
How to delete or copy alternative rows/columns at a time? Bhagavan Excel Discussion (Misc queries) 0 May 12th 08 07:31 PM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
subtotal copy-paste and delete hidden rows Winslow Excel Discussion (Misc queries) 1 December 12th 06 03:26 PM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM


All times are GMT +1. The time now is 03:15 AM.

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

About Us

"It's about Microsoft Excel"