Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将数据粘贴到新工作表上,所有单元格都将隐藏_Vba_Excel - Fatal编程技术网

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

Vba 将数据粘贴到新工作表上,所有单元格都将隐藏,vba,excel,Vba,Excel,由于某种原因,每次我运行此代码时,它都会隐藏新工作表上的所有数据。 行高度设置为0 我必须使用鼠标拖动行高,使最后一个单元格可见,然后从那里我可以单击一个单元格并“获取”数据 我怎样才能解决这个问题?这很烦人。 这与我的代码有关,还是像这样粘贴数据后需要设置行高 编辑:代码窗格: 根据聊天,快速解决方案是: 'Other option is to simply copy/paste the sheet NumMax = NumMax + 1 'there is more code above

由于某种原因,每次我运行此代码时,它都会隐藏新工作表上的所有数据。
行高度设置为0

我必须使用鼠标拖动行高,使最后一个单元格可见,然后从那里我可以单击一个单元格并“获取”数据

我怎样才能解决这个问题?这很烦人。
这与我的代码有关,还是像这样粘贴数据后需要设置行高

编辑:代码窗格:

根据聊天,快速解决方案是:

'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
值得注意的是,这总是一个好主意


此外,这还没有解决隐藏在
PasteSpecial
上的行的非常奇怪的问题。。。但是哦,好吧,如果它起作用,它就起作用了。

试着在代码的末尾添加
工作表(“XCFIL”&NumMax)。Cells.RowHeight=10
。这就是全部代码吗?在
Range(“A1”).选择
后会发生什么?在我发布此问题的同时,我尝试了此
工作表(“XCFIL_1”).Range(“A1:A”&Rows.Count).Rows.AutoFit
,计算机仍在运行代码。现在大约完成了25%。@BruceWayne代码将工作表Resultat复制到Resultat_1并更新透视表。简言之,是的,仅此而已。要么源工作表(“XCFIL”)隐藏了所有行,要么在每个新工作表中都有一些工作簿事件处理程序隐藏了行。@Andreas不客气!出于好奇,第二个宏可以工作吗?我很想知道是否如此,以及这些行是否仍然可见。不需要花太多时间,但如果你还有几分钟的时间,我很想知道。我稍后会尝试,现在没有时间做。@Andreas-Yay!很高兴两个版本都能用。。。我仍然很好奇为什么你的原始代码隐藏了所有的行。我知道你有一个有效的解决方案,所以也许当你觉得无聊的时候,你介意帮我试一下,让我知道它是怎么回事吗?在我发布的第二个宏中,将最后一行(
destWS.Range(…).Value=copyRng.Value
更改为:
copyRng.Copy
,然后下一行
destWS.Range(“A1”).pasteAll
并查看它是否隐藏行。我猜不会,但谁知道呢!
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