Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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
Excel VBA将特定单元格复制并粘贴到另一张图纸上_Excel_Vba - Fatal编程技术网

Excel VBA将特定单元格复制并粘贴到另一张图纸上

Excel VBA将特定单元格复制并粘贴到另一张图纸上,excel,vba,Excel,Vba,我想看看某个特定的单元格是否是我期望的值,如果是,我想将其粘贴到另一张图纸上。但我的代码不知怎么出了问题。 这是我的密码: Private Sub CommandButton1_Click() Sheets("Sheet3").Select If Cells(2,6).Value == 25 Then Cells(2, 6).Select Selection.Copy Sheets("Sheet1").Select

我想看看某个特定的单元格是否是我期望的值,如果是,我想将其粘贴到另一张图纸上。但我的代码不知怎么出了问题。 这是我的密码:

Private Sub CommandButton1_Click()

    Sheets("Sheet3").Select
    If Cells(2,6).Value == 25 Then
        Cells(2, 6).Select
        Selection.Copy

        Sheets("Sheet1").Select
        Cells(4, 1).Paste
    End If

End Sub

VBA使用单个=符号进行比较

Private Sub CommandButton1_Click()
    If workSheets("Sheet3").Cells(2,6).Value = 25 Then
        workSheets("Sheet1").Cells(4, 1) = 25
    End If
End Sub

您可以编写一个交互式窗口来输入可能更改的值

Private Sub CommandButton1_Click()

    Dim exp_val As Integer
    exp_val = InputBox("What's the value you expect?")
    If Worksheets("Sheet3").Cells(2, 6).Value = exp_val Then
        Worksheets("Sheet2").Cells(4, 1).Value = exp_val
    End If

End Sub
Private Sub CommandButton1_Click()

    Dim exp_val As Integer
    exp_val = InputBox("What's the value you expect?")
    If Worksheets("Sheet3").Cells(2, 6).Value = exp_val Then
        Worksheets("Sheet2").Cells(4, 1).Value = exp_val
    End If

End Sub