【发布时间】:2017-05-16 04:20:57
【问题描述】:
我很难创建一个宏,它将一行数据从一个工作表复制到另一个工作表,然后立即删除复制的数据源并向上移动下面的行以清除剩余的空白/空行。此工作簿的上下文是一个请求跟踪器,一旦请求具有完成日期,在一定时间段(30 天)后,该请求将被复制到“历史请求”表中。紧接着,活动页面上的原始复制数据将被删除,其他所有内容都“向上移动”以清除留下的空白。这是我已经开发的,当然还有一些帮助......如果有人可以提供帮助,将不胜感激。
Public Sub DataBackup()
Dim RowDate
Dim CurrentDate
Dim Interval
Dim CurrentAddress
Dim ValueCellRange As Range
Dim ValueCell As Range
Dim ws As Worksheet
'Interval set to an appropriate number of days
Interval = 30
CurrentDate = Now()
For Each ws In Worksheets
Set ValueCellRange = ws.Range("U3:U130")
For Each ValueCell In ValueCellRange
If ValueCell.Value <> "" Then
If CurrentDate - ValueCell.Value >= Interval Then
Rows(ActiveCell.Row).Select
Sheets("Historical Requests").Select
ActiveSheet.Paste
ValueCell.EntireRow.ClearContents
End If
End If
Next ValueCell
Next ws
'Clear variable value for next initialization
Set ValueCell = Nothing
End Sub
【问题讨论】:
-
这是所有的代码,还是你被困在如何做其中的一部分?另外,我强烈建议研究[如何避免使用
.Select/.Activate](https://stackoverflow.com/questions/10714251/) as it will help cut down on the code and be more direct in working with the data. Also, you should put the worksheet beforeRows(...).Select`,否则它只会选择/使用活动表上的行。
标签: vba excel copy copy-paste