我有一個運行時錯誤91,我不知道爲什麼。我將這段代碼用於一個不同的工作簿,它的工作原理非常完美,列中的信息與我正在提取的不同,但我將所有列和範圍都更改爲正確的列,但現在我在這裏以及唯一一個區別在於,請幫忙!運行時錯誤91
Range(Cells(20, 1), Cells(LastRow, LastCol)).Select
Selection.AutoFilter
Range("C2").Select
即開始,但這裏是哪裏發生了錯誤:
ActiveWorkbook.Worksheets(msheet).AutoFilter.Sort.SortFields. _
Add Key:=Range("A20:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
請幫幫忙,我不知道我錯過了什麼。謝謝!
這裏是代碼的開頭:
Sub getdata()
Dim mastername As String
Dim count As Long
Dim match As Long
Dim repeat As Long
Dim path As String
Dim status As String
Dim name As String
Dim mpath As String
Dim cpath As String
Dim LastRow As Long
Dim LastCol As Integer
Dim mbank As String
Dim mname As String
mpath = Sheets("Master log").Cells(14, "W").Value
mname = Sheets("Master log").Cells(15, "W").Value
msheet = Sheets("Master log").Cells(16, "W").Value
Sheets("MGPR1").Range("A1:AA50000").ClearContents
name = Application.ActiveWorkbook.name
cpath = Application.ActiveWorkbook.path & "\"
Windows(name).Activate
'--open Management report workbook if not already open
If CheckFileIsOpen(mname) = False Then
Workbooks.Open mpath & mname
End If
'-------------------------------------------
Windows(mname).Activate
Sheets(msheet).Select
'select full data
With ActiveSheet
LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
End With
With ActiveSheet
' LastCol = .Cells(1, .Columns.count).End(xlToLeft).Column
LastCol = 20
End With
需要更多的細節。你的第一個代碼看起來像是對大範圍進行排序,但是你的第二個代碼只是對列A進行排序。另外,什麼是'msheet'?它是你定義的變量嗎?如果它是工作表的名稱,那麼使用'Sheets(「msheet」)' – Chrismas007 2014-11-14 21:38:47
根據錯誤,我認爲它與'msheet'周圍缺少引號有關。 – Chrismas007 2014-11-14 21:41:52
Dim s As Worksheet Set s = Worksheets(1)... msheet可以是索引嗎? – dee 2014-11-14 21:46:22