问题描述
输入新行后,我希望它自动创建新表,该表的名称写在该行的标题栏中(对于第一行,创建名称为“ M”的表) 还将M行中的所有数据复制到新工作表中
我知道有办法
=<SheetName>!<cell>
,但是如果我有1000列,这并没有真正的帮助,
我必须创建1000张纸,然后复制1000次!
仅此而已,谢谢。 也可以随意使用任何方法(例如VBA)。
解决方法
我认为这可能很麻烦,特别是如果您最终获得大量数据。下面的代码将允许您运行一个宏,该宏将根据数据快速创建工作表。此宏只能运行一次,但可以完成工作
Sub CopyRowsToSheet()
' Variables needed for the formula
Dim NofRows As Long
Dim i As Long
Dim iActive As Boolean
' Counting the number of Rows in the active sheet
With ActiveSheet
NofRows = .Range("A" & Rows.Count).End(xlUp).Row
' Cycling through the number of rows on the active sheet
' we have set i = 2 as there is a header on the first page. If there is no header then set i = 1
For i = 2 To NofRows
' Creating the new sheet
Worksheets.Add(,Sheets(Sheets.Count)).Name = "Row " & i
' Copy Data to new sheet
.Rows(i).Copy Sheets("Row " & i).Range("A1:D1")
Next i
End With
End Sub
抱歉,不能100%知道如何自动执行此操作,但是如果我找到一种方法,我会在这里为您添加