我在第一行尝试复制以下VBA中的值时出错,我认为范围的第二部分是错误的,但无法检测到问题。
Dim site As String
Dim People As Range
Dim AmountOfSites As Long
Dim AmountOfPeople As Long
Dim DestStartRow As Long
Dim DestEndRow As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim sh3 As Worksheet
Set sh1 = ThisWorkbook.Sheets("SiteName")
Set sh2 = ThisWorkbook.Sheets("Input")
Set sh3 = ThisWorkbook.Sheets("Output")
AmountOfSites = sh1.Range("A1048576").End(xlUp).Row
AmountOfPeople = sh2.Range("A1048576").End(xlUp).Row
DestStartRow = 2
DestEndRow = DestStartRow + AmountOfPeople
For i = 1 To AmountOfSites
sh3.Range(Cells(DestStartRow, "A"), Cells((DestEndRow), "L")).Value = _
sh2.Range(Cells(2, "A"), Cells(AmountOfPeople + 2, "L")).Value
sh3.Range(Cells(DestStarRow, "M"), Cells(DestEndRow, "M")).Value = sh1.Cells(i, "A")
DestStartRow = DestEndRow + 1
DestEndRow = DestStarRow + AmountOfPeople
Next
答案 0 :(得分:2)