将数据粘贴到新工作表上,并隐藏所有单元格

由于某种原因,每次运行这个代码时,它都隐藏了新工作表中的所有数据。
行高被设置为0。

我必须使用鼠标拉行高,使最后一个单元格可见,然后从那里我可以点击一个单元格,“起床”的数据。

我怎样才能解决这个问题? 这非常烦人
这是与我的代码的东西,或者我需要粘贴这样的数据后设置行高?

在这里输入图像说明

在这里输入图像说明

NumMax = NumMax + 1 'there is more code above that sets NumMax ThisWorkbook.Activate ThisWorkbook.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count)).Name = "XCFIL_" & NumMax ThisWorkbook.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count)).Name = "Resultat_" & NumMax Sheets("XCFIL").Activate Cells.Copy Sheets("XCFIL_" & NumMax).Activate Range("A1").PasteSpecial xlPasteAll Range("A1").Select ' a try to get up in the sheet, but it does not work 

编辑:代码窗格: 在这里输入图像说明

通过聊天,一个快速的解决scheme是:

 'Other option is to simply copy/paste the sheet NumMax = NumMax + 1 'there is more code above that sets NumMax With ThisWorkbook .Sheets("XCFIL").Copy After:=.Sheets(.Sheets.Count) ActiveSheet.Name = "XCFIL_" & NumMax End With 

但是,我正在研究下面,这可能也会起作用。

 Sub t() Dim originWS As Worksheet, destWS As Worksheet Dim NumMax As Long NumMax = NumMax + 1 'there is more code above that sets NumMax With ThisWorkbook Set originWS = .Sheets("XCFIL") Set destWS = .Sheets.Add(After:=.Sheets(.Sheets.Count)) destWS.Name = "XCFIL_" & NumMax End With Dim copyRng As Range Dim lastCol As Long, lastRow As Long With originWS lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row Set copyRng = .Range(.Cells(1, 1), .Cells(lastRow, lastCol)) 'assuming your data starts in A1 End With destWS.Range(destWS.Cells(1, 1), destWS.Cells(lastRow, lastCol)).Value = _ copyRng.Value End Sub 

注意, 避免使用.Select / .Activate总是一个好主意。

此外,这并没有得到隐藏在PasteSpecial行的非常古怪的问题。 …但是,哦,如果它工作,它的工作。