當你設置單元格給定的範圍內,你不需要選擇它。相反,你可以參考它。如果您還設置工作表對象,您希望最終將其粘貼到,上述然後可以寫得更緊湊和直接的方式,而不會選擇:
Sub test()
Set cell = Range("A2") 'implicit reference to activesheet in activeworkbook
Set ws1 = Sheets("one") 'requires that you have a sheet named "one" in the activeworkbook
Set ws2 = Sheets("two") 'requires that you have a sheet named "two" in the activeworkbook
'assign the value to somewhere in the ws1 and ws2
ws1.Range("A2") = cell
ws2.Range("A2") = cell
End Sub
編輯:使用複製
版,保留公式
Sub test()
Set cell = Range("A2") 'implicit reference to activesheet in activeworkbook
Set ws1 = Sheets("one") 'requires that you have a sheet named "one" in the activeworkbook
Set ws2 = Sheets("two") 'requires that you have a sheet named "two" in the activeworkbook
'assign the value to somewhere in the ws1 and ws2
cell.Copy Destination:=ws1.Range("A2")
cell.Copy Destination:=ws2.Range("A2")
End Sub