vba 运行出错(运行时错误‘1004’)调试没错误,我不知道哪句出错了?
Subqs()Application.DisplayAlerts=FalseApplication.ScreenUpdating=FalseForch=4ToRange(...
Sub qs()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For ch = 4 To Range("A65536").End(xlUp).Row
bj = Range("A" & ch).Value
mfile = ThisWorkbook.Path + "\" & Left(bj, 1) + "年级\" & Left(bj, 1) + "年级.xls"
If Dir(mfile) <> "" Then
bs = 0
Do While InStr(Range("A" & ch + bs).Value, Left(bj, 1))
bs = bs + 1
Loop
Workbooks.Open (mfile)
For i = 1 To bs
sj = ActiveSheet.Range("A:A").Find(Left(bj, 1) & "(" + CStr(i) & ")").Row
With Workbooks(1).Sheets(1)
.Range("B" & ch) = ActiveSheet.Range("B" & sj)
.Range("D" & ch) = ActiveSheet.Range("C" & sj)
.Range("F" & ch) = ActiveSheet.Range("D" & sj)
.Range("H" & ch) = ActiveSheet.Range("E" & sj)
.Range("E" & ch).Formula = "=Round($B" & ch & "* F" & ch & ",0)"
.Range("E" & ch).Copy .Range("G" & ch)
.Range("L" & ch) = ActiveSheet.Range("G" & sj)
.Range("N" & ch) = ActiveSheet.Range("H" & sj)
.Range("P" & ch) = ActiveSheet.Range("I" & sj)
.Range("E" & ch).Copy .Range("M" & ch)
.Range("E" & ch).Copy .Range("O" & ch)
If ActiveSheet.Range("K" & sj) > "" Then
.Range("T" & ch) = ActiveSheet.Range("K" & sj)
.Range("V" & ch) = ActiveSheet.Range("L" & sj)
.Range("X" & ch) = ActiveSheet.Range("M" & sj)
.Range("E" & ch).Copy .Range("U" & ch)
.Range("E" & ch).Copy .Range("W" & ch)
End If
If ActiveSheet.Range("O" & sj) > "" Then
.Range("AB" & ch) = ActiveSheet.Range("O" & sj)
.Range("AD" & ch) = ActiveSheet.Range("P" & sj)
.Range("AF" & ch) = ActiveSheet.Range("Q" & sj)
.Range("E" & ch).Copy .Range("AC" & ch)
.Range("E" & ch).Copy .Range("AE" & ch)
End If
If ActiveSheet.Range("S" & sj) > "" Then
.Range("AJ" & ch) = ActiveSheet.Range("S" & sj)
.Range("AL" & ch) = ActiveSheet.Range("T" & sj)
.Range("AN" & ch) = ActiveSheet.Range("U" & sj)
.Range("E" & ch).Copy .Range("AK" & ch)
.Range("E" & ch).Copy .Range("AM" & ch)
End If
End With
ch = ch + 1
Next
ActiveWorkbook.Close
Workbooks(1).Sheets(1).Activate
Range("I" & ch).Formula = "=IF(ISERROR(AVERAGE(I" & ch - bs & ":I" & ch - 1 & "))," & Chr(34) & Chr(34) & ",AVERAGE(I" & ch - bs & ":I" & ch - 1 & "))"
Cells(ch, 9).Copy Cells(ch, 17)
Cells(ch, 9).Copy Cells(ch, 25)
Cells(ch, 9).Copy Cells(ch, 33)
Cells(ch, 9).Copy Cells(ch, 41)
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub 展开
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For ch = 4 To Range("A65536").End(xlUp).Row
bj = Range("A" & ch).Value
mfile = ThisWorkbook.Path + "\" & Left(bj, 1) + "年级\" & Left(bj, 1) + "年级.xls"
If Dir(mfile) <> "" Then
bs = 0
Do While InStr(Range("A" & ch + bs).Value, Left(bj, 1))
bs = bs + 1
Loop
Workbooks.Open (mfile)
For i = 1 To bs
sj = ActiveSheet.Range("A:A").Find(Left(bj, 1) & "(" + CStr(i) & ")").Row
With Workbooks(1).Sheets(1)
.Range("B" & ch) = ActiveSheet.Range("B" & sj)
.Range("D" & ch) = ActiveSheet.Range("C" & sj)
.Range("F" & ch) = ActiveSheet.Range("D" & sj)
.Range("H" & ch) = ActiveSheet.Range("E" & sj)
.Range("E" & ch).Formula = "=Round($B" & ch & "* F" & ch & ",0)"
.Range("E" & ch).Copy .Range("G" & ch)
.Range("L" & ch) = ActiveSheet.Range("G" & sj)
.Range("N" & ch) = ActiveSheet.Range("H" & sj)
.Range("P" & ch) = ActiveSheet.Range("I" & sj)
.Range("E" & ch).Copy .Range("M" & ch)
.Range("E" & ch).Copy .Range("O" & ch)
If ActiveSheet.Range("K" & sj) > "" Then
.Range("T" & ch) = ActiveSheet.Range("K" & sj)
.Range("V" & ch) = ActiveSheet.Range("L" & sj)
.Range("X" & ch) = ActiveSheet.Range("M" & sj)
.Range("E" & ch).Copy .Range("U" & ch)
.Range("E" & ch).Copy .Range("W" & ch)
End If
If ActiveSheet.Range("O" & sj) > "" Then
.Range("AB" & ch) = ActiveSheet.Range("O" & sj)
.Range("AD" & ch) = ActiveSheet.Range("P" & sj)
.Range("AF" & ch) = ActiveSheet.Range("Q" & sj)
.Range("E" & ch).Copy .Range("AC" & ch)
.Range("E" & ch).Copy .Range("AE" & ch)
End If
If ActiveSheet.Range("S" & sj) > "" Then
.Range("AJ" & ch) = ActiveSheet.Range("S" & sj)
.Range("AL" & ch) = ActiveSheet.Range("T" & sj)
.Range("AN" & ch) = ActiveSheet.Range("U" & sj)
.Range("E" & ch).Copy .Range("AK" & ch)
.Range("E" & ch).Copy .Range("AM" & ch)
End If
End With
ch = ch + 1
Next
ActiveWorkbook.Close
Workbooks(1).Sheets(1).Activate
Range("I" & ch).Formula = "=IF(ISERROR(AVERAGE(I" & ch - bs & ":I" & ch - 1 & "))," & Chr(34) & Chr(34) & ",AVERAGE(I" & ch - bs & ":I" & ch - 1 & "))"
Cells(ch, 9).Copy Cells(ch, 17)
Cells(ch, 9).Copy Cells(ch, 25)
Cells(ch, 9).Copy Cells(ch, 33)
Cells(ch, 9).Copy Cells(ch, 41)
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub 展开
1个回答
天正软件
2024-08-02 广告
2024-08-02 广告
天正软件可以解决以下问题:1. 提供设计标准化:天正软件专注于勘察设计领域,为用户提供标准化、信息化、智能化的解决方案,以提高设计效率、优化设计流程、降低成本。2. 提高绘图效率:天正软件提供了一系列专业绘图工具,能够帮助设计师快速绘制图纸...
点击进入详情页
本回答由天正软件提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询