我无法找到一个确保将一个工作表中的可见单元格复制到新工作簿中。我的初始工作簿已过滤。有点像:
Sub RangeToNew()
Dim newBook as Workbook
Set newBook = Workbooks.Add
ThisWorkbook.Worksheets("worksheet").SpecialCells(xlCellTypeVisible).Copy _
Before:=newBook.Worksheets(1)
End Sub
这不起作用。
答案 0 :(得分:3)
看起来您需要先将SpecialCells范围设置为Range对象,然后再进行复制。试试这个:
Sub rangeToNew_Try2()
Dim newBook As Excel.Workbook
Dim rng As Excel.Range
Set newBook = Workbooks.Add
Set rng = ThisWorkbook.Worksheets("Sheet1").Cells.SpecialCells(xlCellTypeVisible)
rng.Copy newBook.Worksheets("Sheet1").Range("A1")
End Sub