-2
您好我有一個有效的範圍對象,但我得到的對象所需錯誤檢查,如果對象爲空,但仍然得到錯誤
Dim row As Integer
Dim col As Integer
If Not rng Is Nothing Then
row = rng.row
col = rng.Column
End If
它進入,如果但(組行= rng.row)線得到錯誤
整個代碼是這樣的:
Dim str() As String
str = GetArray(ActiveSheet.Range("A3"))
Dim element As Variant
Dim rng As Range
Set rng = Range("D3")
For Each element In str
With ActiveSheet.QueryTables.Add(Connection:= _
element, _
Destination:=rng)
.Name = "technicals_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Range(Cells(rng.row, rng.Column), Cells(rng.row + 70, rng.Column + 1)).Select
Selection.Copy
rng.Offset(0, 2).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, transpose:=True
Range(Cells(rng.row, rng.Column), Cells(rng.row + 70, rng.Column + 1)).Select
Selection.QueryTable.Delete
Selection.Delete Shift:=xlToLeft
/* AFTER THIS LINE I GET OBJECT REQUIRED ERROR */
Range(Cells(rng.row, rng.Column), Cells(rng.row, rng.Column + 70)).Select
Selection.Delete Shift:=xlUp
Set rng = rng.Offset(1, 0)
Next element
End Sub
我已經編輯它,請再讀一遍 請閱讀我輸入此評論的部分:
/*此行後,我得到對象必需的錯誤*/
我該怎麼辦? 謝謝
你剛剛刪除了範圍,所以你不能引用它。你知道這是D3,所以使用行號/列號。 – Rory 2014-09-19 12:59:32
那麼我應該怎麼做才能避免 – 2014-09-19 13:01:54
請幫我.. – 2014-09-19 13:12:47