![](/img/trans.png)
[英]Excel VBA: Copy and Paste Specific Cell from Another Workbook Loop
[英]Excel VBA copy and paste a specific cell to another Sheet
我想查看特定的單元格是否是我期望的值,如果是的話,我想將其粘貼到另一張紙上。 但是我的代碼以某種方式出錯了。 這是我的代碼:
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
Private Sub CommandButton1_Click()
With Sheets("Sheet3")
If .Cells(2, 6).Value = 25 Then
.Cells(2, 6).Copy Sheets("Sheet1").Cells(4, 1)
End If
End With
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.