1
我得到一個運行時錯誤,當我運行下面的代碼:運行時錯誤:1004應用程序定義或對象定義的錯誤
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.DisplayStatusBar = False
Application.EnableEvents = False
Dim c, OrgList, vtList, FndRng As Range
Dim Tbl As ListObject
Dim NewRow As ListRow
Dim Org, Track As Worksheet
Set Org = ActiveWorkbook.Worksheets("Org List")
Set Track = ActiveWorkbook.Worksheets("Visit Tracking Sheet")
Set Tbl = Track.ListObjects("TrackTbl")
Set OrgList = Org.Range(Cells(2, 1), Cells(Org.UsedRange.Rows.Count, 1))
Set vtList = Track.Range("TrackTbl[Org ID]")
一切都正常運行,直到我去Set ChngList = Track.Range("TrackTbl[Org ID]")
會拋出Run-time Error: 1004
。我也曾嘗試以下替換線,所有這些都拋出了同樣的錯誤:
Set vtList = Tbl.Range(Cells(2, 1), Cells(ListRows.Count, 1))
Set vtList = Track.Range(Cells(2, 1), Cells(Track.UsedRange.Rows.Count, 1))
Set vtList = Track.Tbl.Range(Cells(2, 1), Cells(ListRows.Count, 1))
Set vtList = Tbl.Range
我在這個虧損一個並且很難找到解決方案。我認爲這是在表中設置範圍引用單元格的問題,但我不確定。
代碼的其餘部分在哪裏?我沒有看到你在哪裏定義'ChngList' – dwirony
請看看[this](https://stackoverflow.com/questions/36368220/is-the-in-range-necessary-when-defined-by-cells)的答案你的問題 –
@dwirony對不起,這應該說'Set vtList',因爲它顯示在我發佈的代碼的最後一行。 –