简体   繁体   English

在Excel中使用VBA,将单元格行移至“主”

[英]Using VBA in Excel, move rows of cells to Master

Using VBA, how can I have users automatically, before save, move (not copy) row(s) of data from their sheet to last row of master? 使用VBA,如何在存储之前将用户的数据行自动从其工作表移动(而不是复制)到主文件的最后一行?

5 individual sheets/users inputting same type of data (tracking their programming data). 5个单独的工作表/用户输入相同类型的数据(跟踪他们的编程数据)。 When user saves, their rows of data on their sheet needs to be moved to master sheet for further analysis. 用户保存时,需要将其工作表上的数据行移至主表以进行进一步分析。 These rows once moved should not exist in individual sheet. 一旦移动,这些行就不应存在于单个工作表中。

Thank you, in advance for any help. 预先感谢您的任何帮助。

My comment may not have been clear, I meant Cut-Paste as part of your function like this ... 我的评论可能不清楚,我的意思是像这样将剪切粘贴作为您功能的一部分...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim Master As Worksheet
Dim LastRow_Master As Integer
Dim LastRow_Current As Integer

Set Master = ThisWorkbook.Worksheets("Master")

For Each ws In ThisWorkbook.Worksheets
   If Not ws Is Master Then
      LastRow_Master = Master.Cells(Master.Rows.Count, 1).End(xlUp).Row + 1
      LastRow_Current = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row

      If LastRow_Current > 1 Then
         ws.Rows("2:" & LastRow_Current).Cut Master.Rows(LastRow_Master)
      End If

   End If
Next

Application.CutCopyMode = 0

End Sub  

Note: I assume every worksheet has a header at Row 1. Including the Master. 注意:我假设每个工作表在第1行都有一个标题,包括母版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM