我想将工作表1中单元格区域中的值粘贴到先前选择/激活的工作表中设置的特定范围中。因此,我希望它仅粘贴到区域B1之前,但只能粘贴到工作表Sheet2,Sheet3,而不是工作表Sheet4,因为我没有在工作簿中选择它。
Sub CopyFirstRow()
Dim Wb As Workbook
Dim Sht As Worksheet
Dim mySelectedSheets As Sheets
Wb.Sheets("Global").Range("B1", "Q39").Copy
Set mySelectedSheets = ActiveWindow.SelectedSheets
For Each Sht In mySelectedSheets
ActiveSheet.Paste
Sht.Range("B1").PasteSpecial xlPasteValues
Next
Application.CutCopyMode = False
End With
End With
End Sub
请解释我在做错什么,因为我试图了解越来越多的VBA,尤其是SET,FOR和WITH函数。
答案 0 :(得分:0)
您使wb变暗了,但从未设置工作簿。
您有两个“结尾为”但没有开头的“开头”
您拥有Activesheet.paste,但尚未选择工作表
Sub Button1_Click()
Dim Wb As Workbook
Dim Sht As Worksheet
Dim mySelectedSheets As Sheets
Set Wb = ThisWorkbook
Wb.Sheets("Global").Range("B1", "Q39").Copy
Set mySelectedSheets = ActiveWindow.SelectedSheets
For Each Sht In mySelectedSheets
Sht.Range("B1").PasteSpecial xlPasteValues
Next
Application.CutCopyMode = False
End Sub