Vba Range Object_工作表的方法失败将数据从一个工作表复制和粘贴到另一个工作表时出错

Vba Range Object_工作表的方法失败将数据从一个工作表复制和粘贴到另一个工作表时出错,vba,excel,Vba,Excel,我正在尝试将数据从输入表复制并粘贴到输出表中,一旦数据进入下一个电子表格,它将从开始日期填充到结束日期的下一行 按原样,代码在调试时会出现以下错误: ws1.Range(“A”&NextRow)=范围对象的方法\u工作表失败;ws1.Range(“B”和NextRow)也一样;ws1.范围(“C”&NextRow)等 ws1.Cells(LastRow,“H”)=应用程序定义的或对象定义的错误 另外,我注意到,当我设置RawDataEntries时,它等于37,这是最后一个非空行,但当我尝试使用

我正在尝试将数据从输入表复制并粘贴到输出表中,一旦数据进入下一个电子表格,它将从开始日期填充到结束日期的下一行

按原样,代码在调试时会出现以下错误: ws1.Range(“A”&NextRow)=范围对象的方法\u工作表失败;ws1.Range(“B”和NextRow)也一样;ws1.范围(“C”&NextRow)等

ws1.Cells(LastRow,“H”)=应用程序定义的或对象定义的错误

另外,我注意到,当我设置RawDataEntries时,它等于37,这是最后一个非空行,但当我尝试使用For循环并将鼠标指向RawDataEntries in For n=1时,VBA会返回105的值,这似乎是无中生有的

我认为代码背后的逻辑是正确的。可能出了什么问题

Sub AddFlight_Click()
Const RNG_END_DT As String = "N2"
Dim NextRow1 As Long, LastRow1 As Long, ws1 As Worksheet
Dim ws2 As Worksheet, RawDataEntries As Long


Set ws1 = Sheets("JetAir Flight Plan")
Set ws2 = Sheets("TUI B Flight Plan")
LastRow1 = ws1.Range("A" & Rows.Count).End(xlUp).Row
NextRow1 = LastRow1 + 1
RawDataEntries = ws2.Range("A" & Rows.Count).End(xlUp).Row

For n = 1 To RawDataEntries

'Data from an input worksheet is copied and pasted into specific cells in an output worksheet.

    ws1.Range("A" & NextRow).Value = ws2.Range("A" & n).Value
    ws1.Range("B" & NextRow).Value = ws2.Range("B" & n).Text
    ws1.Range("D" & NextRow).Value = ws2.Range("D" & n).Text
    ws1.Range("E" & NextRow).Value = ws2.Range("E" & n).Text
    ws1.Range("F" & NextRow).Value = ws2.Range("F" & n).Text
    ws1.Range("G" & NextRow).Value = ws2.Range("G" & n).Text
    ws1.Range(RNG_END_DT).Value = ws2.Range("H" & n).Value

'A series of dates is created from a starting date
'    to an ending date in column A of ws1.

    ws1.Range("A" & NextRow).DataSeries Rowcol:=xlColumns, _
        Type:=xlChronological, Date:=xlDay, Step:=7, _
        Stop:=ws1.Range(RNG_END_DT).Value, Trend:=False

'The data filled in the last row with the userform data through
' the first part of the macro will be copied and pasted in
' the next row until there is a blank cell in column A.

    LastRow1 = ws1.Range("A" & Rows.Count).End(xlUp).Row
    ws1.Range(ws1.Range("B" & NextRow), ws1.Cells(LastRow, "H")).FillDown

'We repeat the process for other rows on the sheet data are pulled from

Next n

非常感谢

将NextRow更改为NextRow1。现在您正在调用一个不存在的变量

或者你可以做相反的事情(NextRow1到NextRow)

与LastRow和LastRow1相同