这个代码大约一个月前就没有任何问题。
运行时错误(#13)指向:
lastRow = Application.Match(校园,subject.Range(“A1:A35000”),1)+ 2
我已经运行了几次宏,有些时候部分成功了。其他时候它根本没有得到任何数据。
如果宏部分成功,如果列中的数据完全相同,那么会导致类型不匹配的原因。从SQL Tools导出的所有数据,然后复制并粘贴到工作表。
Dim lastRow As Long
Dim firstRow As Long
Dim count As Long
Dim campus As String
Dim gradeCount As Integer
Dim current As String
Dim previous As String
campus = schools.Range("A" & i).Value
With subject.Range("A:A")
Set Rng = .Find(what:=campus, _
After:=.Cells(.Cells.count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
gradeCount = 0
firstRow = 0
If Not Rng Is Nothing Then
firstRow = Application.Match(campus, subject.Range("A1:A35000"), 0) + 2
lastRow = Application.Match(campus, subject.Range("A1:A35000"), 1) + 2
gs.Range("A" & rowCount).Value = schools.Range("A" & i).Value
gs.Range("C" & rowCount).Value = schools.Range("C" & i).Value
currentCampus = gs.Range("A" & rowCount).Value
current = ""
previous = ""
For count = firstRow To lastRow
If campus = subject.Range("A" & count).Value Then
current = subject.Range("C" & count)
gs.Range("A" & rowCount).Value = schools.Range("A" & i).Value
If current <> previous Then
gs.Range("C" & rowCount).Value = schools.Range("C" & i).Value
gs.Range("D" & rowCount).Value = grade
gs.Range("E" & rowCount).Value = current
previous = current
gradeCount = gradeCount + 1
rowCount = rowCount + 1
End If
End If
Next count
If gradeCount > 1 Then
gs.Range("D" & rowCount).Value = grade
gs.Range("E" & rowCount).Value = "*"
gs.Range("C" & rowCount).Value = schools.Range("C" & i).Value
rowCount = rowCount + 1
End If
End If
End With
答案 0 :(得分:0)
这表示匹配无法找到值。
如果相同的公式占用了工作表单元格,您会看到:
#N/A