excel下标越界

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:21:38
提示:Set ws = Worksheets(name)下标越界,请教大侠如何解决呀!!?

Sub processOneSheet(name As String, ws2 As Worksheet, ByRef nextRow As Integer)
Dim ws As Worksheet
Dim i As Integer, blankCount As Integer
Dim isFirstRow As Boolean

Set ws = Worksheets(name)
blankCount = 0
isFirstRow = True

For i = 3 To 1000
If (Len(ws.Cells(i, "N").Value) = 0 And Len(ws.Cells(i, "U").Value) = 0) Then
blankCount = blankCount + 1
If blankCount > 10 Then
GoTo PROCESS_ONE_SHEET_AFTER_FOR
End If
GoTo PROCESS_ONE_SHEET_BEFORE_NEXT_I
End If

Sub processOneSheet(name As String, ws2 As Worksheet, ByRef nextRow As Integer)
Dim ws As Worksheet
Dim i As Integer, blankCount As Integer
Dim isFirstRow As Boolean
dim j as integer

Set ws = Worksheets(name)
blankCount = 0
isFirstRow = True

j = Range("N65536").End(xlUp).Row

For i = 3 To j
If (Len(ws.Cells(i, "N").Value) = 0 And Len(ws.Cells(i, "U").Value) = 0) Then
blankCount = blankCount + 1
If blankCount > 10 Then
GoTo PROCESS_ONE_SHEET_AFTER_FOR
End If
GoTo PROCESS_ONE_SHEET_BEFORE_NEXT_I
End If

你再试试

已经提示的很明白了,数组那里For i = 3 To 1000 导致的,1000改小点

不然的话中间加入判断或Try