我正在尝试复制并粘贴包含过滤和一些隐藏列的电子表格中的某一行。出于某种原因,当我的过滤功能打开时,Excel不会复制隐藏的列,当我粘贴行时,它会省略隐藏的列。
此问题有解决方法吗?也许是一个秘密的快捷方式,可以复制选择中的所有单元格
感谢。
答案 0 :(得分:1)
这里简单的解决方案(你也可以遍历工作表并存储隐藏列的索引,但我认为这可能比制作这个复制的工作表需要更多的时间)
Sub CopyHiddenColumns()
Dim DestinationSheet As Worksheet, TempSheet As Worksheet, CopySheet As Worksheet
Set DestinationSheet = ThisWorkbook.Worksheets("DestSheet")
Set CopySheet = ThisWorkbook.Worksheets("CopySheet")
CopySheet.Copy Before:=ThisWorkbook.Worksheets(1)
Set TempSheet = ThisWorkbook.Worksheets(1)
TempSheet.UsedRange.Hidden = False
TempSheet.UsedRange.Copy Destination:= DestinationSheet.Range("A1")
Application.DisplayAlerts = False
TempSheet.Delete
Application.DisplayAlerts = True
End Sub
显然,您可以使用指定的范围而不是UsedRange
和Range("A1")
。我只是将它们作为填充程序放置以允许代码编译
答案 1 :(得分:0)
感谢RGA,我用他的代码玩了一下,得到了这个结果。工作正常,你怎么看?
Sub lev()
Dim ws As Worksheet, temp As Worksheet, copyrange As Range, pasterange As Range
Set ws = ThisWorkbook.ActiveSheet
On Error GoTo nocell
Set copyrange = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
On Error GoTo nocell
Set pasterange = Application.InputBox(Prompt:="Please Select ONE Cell to paste the your selection!", Title:="Range Select", Type:=8)
On Error GoTo 0
ws.Copy before:=ThisWorkbook.ActiveSheet
ActiveSheet.Name = "temp123"
Range("a1", Selection.End(xlToRight)).Select
Selection.EntireColumn.Hidden = False
Range("a1", Selection.End(xlDown)).Select
Selection.EntireRow.Hidden = False
Range(copyrange.Address()).Select
Selection.Copy Destination:=pasterange
Application.DisplayAlerts = False
Sheets("temp123").Delete
Application.DisplayAlerts = True
nocell:
End Sub
此代码可以处理过滤,隐藏行和隐藏列。 实际上,这非常酷且有用。
请让我知道你的想法!