Excel Macro仅将工作表复制到新的工作表粘贴值

  • 本文关键字:工作 复制 Macro Excel excel vba
  • 更新时间 :
  • 英文 :


我正在使用Excel中的宏,该宏将复制当前的工作表并将值粘贴到新的工作表中。工作表的名称仅在数字之后的数字[IE 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

如果数据连续,请考虑创建新表,选择和复制数据范围,然后使用以下代码粘贴到新表上。

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

我使用类似的东西:

Sub KopyKat()
Dim s1 As Worksheet, s2 As Worksheet
Dim r As Range, addy As String
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
For Each r In s1.UsedRange
    If r.Value <> "" Then
        If Not r.HasFormula Then
            addy = r.Address
            r.Copy s2.Range(addy)
        End If
    End If
Next r
End Sub

相关内容

最新更新