我写过vba将50张纸合并到一张主纸上。有用。现在虽然他们需要知道条目来自哪个表格以进行更正。我如何捕获工作表名称?
For Each sh In ActiveWorkbook.Worksheets
If sh.Name <> DestSh.Name
Then Last = Range("A100000").End(xlUp).Row
Set CopyRng = sh.Range("A2:k2" & Cells(Rows.Count, "A").End(xlUp).Row)
If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then
MsgBox "There are not enough rows in the " & _
"summary worksheet to place the data."
GoTo ExitTheSub
End If
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial Paste:=xlPasteValues, skipBlanks:=True
Application.CutCopyMode = False
End With
(CopyRng.Rows.Count).Value = sh.Name
End If
Next
答案 0 :(得分:1)
如果您有范围,并想知道与范围相关联的工作表:
Public Function WhichSheet(r As Range) As String
WhichSheet = ""
If Not r Is Nothing Then
WhichSheet = r.Parent.Name
End If
End Function
答案 1 :(得分:0)
这就是答案......
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial Paste:=xlPasteValues, skipBlanks:=True
Application.CutCopyMode = False
End With
DestSh.Cells(Last + 1, "Q").Resize(CopyRng.Rows.Count).Value = sh.Name
感谢帮助人员。