Home > Software engineering >  Teacher, please help me to see what was wrong with this code? Application error definition or object
Teacher, please help me to see what was wrong with this code? Application error definition or object

Time:09-20

 Sub to () 
Dim As Integer I
Dim j As Integer
For I=0 To 2622
For j=0 To 1165
If (j + 1) Mod 3=0 Then
I=I + 1
ElseIf (j + 1) Mod 2=0 Then
Cells (I, j) Value=https://bbs.csdn.net/topics/j * 50
ElseIf (j + 1) Mod 2 & lt;> 0 And Mod (j + 1) 3 & lt;> 0 Then
Cells (I, j) Value=https://bbs.csdn.net/topics/i * 50
End the If
Next j
Next I


End Sub

Why run error

CodePudding user response:

The
refer to the original poster qq_38255971 response:
Sub to ()
Dim As Integer I
Dim j As Integer
For I=0 To 2622
For j=0 To 1165
If (j + 1) Mod 3=0 Then
I=I + 1
ElseIf (j + 1) Mod 2=0 Then
Cells (I, j) Value=https://bbs.csdn.net/topics/j * 50
ElseIf (j + 1) Mod 2 & lt;> 0 And Mod (j + 1) 3 & lt;> 0 Then
Cells (I, j) Value=https://bbs.csdn.net/topics/i * 50
End the If
Next j
Next I


End Sub
Why run error.

The object of Cells?

CodePudding user response:

Cells object should be a Excel spreadsheet?

CodePudding user response:

Because your Excel version lower...

Run this code, need to Excel 2007 or higher version,
Excel 2003 or the previous version, maximum 256 column data, after the j values greater than 256 Cells (I, j). The Value will go wrong,

In addition, suggest you put the variable I, j is used Long,
Otherwise you the two I * 50, j * 50 "overflow" will cause abnormal,
: (can also change the 50 to 50 & amp; )
  •  Tags:  
  • VBA
  • Related