复制范围宏中的范围错误

时间:2015-11-19 00:50:11

标签: excel vba excel-vba

我在第一行尝试复制以下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

1 个答案:

答案 0 :(得分:2)

来自@Scott Craner

  

所有RangesCells都需要合格。所以sh3.Range(sh3.Cells(...

并且根据OP:

  

YEPS。谢谢!那是它