【发布时间】:2019-02-20 19:15:54
【问题描述】:
我正在使用 Excel 中的宏来制作当前工作表的副本并将值粘贴到新工作表中。工作表名称将与后面的数字相同[即 Sheet, Sheet1(2)]
我的代码正确执行此操作,只是它将所有内容复制并粘贴到 Sheet1(2)。我只希望它将值(不是公式)从 Sheet1 粘贴到 Sheet1(2)。我充其量是 vba 的新手,因此非常感谢任何建议。
Sub SPACER_Button4_Click()
' Compile Button to Generate Quote
'
'variables definitions
ActiveSheetValue = ActiveSheet.Name
'
'This section creates a copy of the active worksheet and names it with the next corresponding number
Sheets(ActiveSheetValue).Copy After:=Sheets(ActiveSheetValue)
'This section should look for X value in each row, column 4. If value equals X, it deletes the row on the copied sheet
Dim i As Integer
i = 26
Do Until i > 300
If ActiveSheet.Cells(i, 11).Value = "X" Then
Rows(i).Delete
Skip = True
End If
'
If Skip = False Then
i = i + 1
End If
'
Skip = False
Loop
'This part hides columns on Right K thru R of new copied sheet
Sheets(ActiveSheet.Name).Range("K:R").EntireColumn.Hidden = True
End Sub
【问题讨论】:
-
只需将值设置为彼此相等 -
Sheets("New Sheet Name").Cells.Value = Sheets("New Sheet Name").Cells.Value?