Home > Software engineering >  Why is no for next
Why is no for next

Time:09-17

Excel in, ask you a great god why
it will next no for?
 Private Sub addBtn_Click () 
Dim CNN As New ADODB. Connection
Dim myStr As String
CNN. The ConnectionString="Provider=SQLOLEDB; User ID=sa; Password=12345678; Server=b0n1q41 \ SQLEXPRESS LAPTOP - 4; The Database=contract "
CNN. Open
The Set Rs_Cate=conn. Execute (" SELECT conNum the from list ")
Arr_Cate=Rs_Cate. GetRows
The Set Rs_Cate=Nothing
Dim Arr_CateNumS, Arr_CateNumI
Arr_CateNumS=UBound (Arr_Cate, 2) 'get the data in an array subscript
For I=3 To Range (" A65536 "). The End (xlUp). Row
For Arr_CateNumI=0 To Arr_CateNumS
If Cells (I, 2). The Value & lt;> "& amp; Arr_Cate (0, Arr_CateNumI) & amp;" Then
Next Arr_CateNumI
ElseIf Cells (I, 2). Value="https://bbs.csdn.net/topics/&Arr_Cate (0, Arr_CateNumI) &" Then
Next I
End the If

CodePudding user response:

The process structure error!

You write code, For statement block and the scope of the If block form "cross"!
"Scope" of various blocks, can only be "nested relations" (or say: contains relationship), cannot cross,

CodePudding user response:

reference 1st floor Chen8013 response:
process structure error!

You write code, For statement block and the scope of the If block form "cross"!
"Scope" of various blocks, can only be "nested relations" (or say: contains relationship), cannot cross,


That if I want to achieve in line with the string without equal conditions continue cycle, have to do

CodePudding user response:

The two For loop, you didn't do anything useful, there is just a "loop"... Meaningful!!!!!!

You just say know you, what is the purpose of let others give you the right advice,

Or: you don't self-righteous "process" of abstracting, the code has nothing to do "think" deleted,
Instead let others think you this code is baffling,

CodePudding user response:

refer to the second floor qq_41340407 response:
Quote: refer to 1st floor Chen8013 response:

The process structure error!

You write code, For statement block and the scope of the If block form "cross"!
"Scope" of various blocks, can only be "nested relations" (or say: contains relationship), cannot cross,


That if I want to achieve in line with the string without equal conditions continue cycle, so what can we do

Which cycle to "continue"? What's going on...

CodePudding user response:

Otherwise, you see such a process, if you can achieve your objective:
 For I=3 To Range (" A65536 "). The End (xlUp). Row 
For Arr_CateNumI=0 To Arr_CateNumS
If Cells (I, 2). Value="https://bbs.csdn.net/topics/&Arr_Cate (0, Arr_CateNumI) &" Then Exit the For
'other operating...
Next Arr_CateNumI
'other operating...
Next I

CodePudding user response:

reference 4 floor Chen8013 response:
Quote: refer to the second floor qq_41340407 response:

Quote: refer to 1st floor Chen8013 response:

The process structure error!

You write code, For statement block and the scope of the If block form "cross"!
"Scope" of various blocks, can only be "nested relations" (or say: contains relationship), cannot cross,


That if I want to achieve in line with the string without equal conditions continue cycle, so what can we do

Which cycle to "continue"? What's going on...


I'm sorry, I'm sorry, but I wanted to loop find excel data database excluded, because they are directly under the excel table space began to add, so find the line does not exist in the database to the line from the beginning line add down
 Private Sub addBtn_Click () 
Dim CNN As New ADODB. Connection
Dim myStr As String
CNN. The ConnectionString="Provider=SQLOLEDB; User ID=sa; Password=12345678; Server=b0n1q41 \ SQLEXPRESS LAPTOP - 4; The Database=contract "
CNN. Open
The Set Rs_Cate=conn. Execute (" SELECT conNum the from list ")
Arr_Cate=Rs_Cate. GetRows
The Set Rs_Cate=Nothing
Dim Arr_CateNumS, Arr_CateNumI
Arr_CateNumS=UBound (Arr_Cate, 2) 'get the data in an array subscript
For I=3 To Range (" A65536 "). The End (xlUp). Row
For Arr_CateNumI=0 To Arr_CateNumS
If Cells (I, 2). The Value & lt;> "& amp; Arr_Cate (0, Arr_CateNumI) & amp;" Then
Next Arr_CateNumI
ElseIf Cells (I, 2). Value="https://bbs.csdn.net/topics/&Arr_Cate (0, Arr_CateNumI) &" Then
Next I
End the If
Dim S As Integer
For the S=I To the Range (" A65536 "). The End (xlUp). Row
For l=1 To Range (" IV1 "). The End (xlToLeft). The Column
If IsNull (Cells (S, l))=True Then
Cells (S, l)=Null
Next l
End the If
Sql="insert into the list of values ('" & amp; Cells (S, 2) & amp; "', '" & amp; Cells (S, 3) _
& "', '" & amp; Cells (S, 4) & amp; "', '" & amp; Cells (S, 5) & amp; "', '" & amp; Cells (S, 6) & amp; "'," & amp; Cells (S, 7) & amp; ", "& amp; Cells (S, 8) & amp; ", '" & amp; Cells (S, 9) & amp; "', '" & amp; Cells (S, 10) & amp; "'," & amp; Cells (11) S, & amp; ", "& amp; Cells (S, 12) & amp; ", '" & amp; Cells (S, 13) & amp; "', '" & amp; Cells (S, 14) & amp; "', '" & amp; Cells (S, 15) & amp; "', '" & amp; Cells (S, 16) & amp; "'," & amp; Cells (S, 17) & amp; ", '" & amp; Cells (S, 18) & amp; "'," & amp; Cells (S, 19) & amp; ", "& amp; Cells (20) S, & amp; ", "& amp; Cells (S, 21) & amp; ", "& amp; Cells (S, 22) & amp; ", "& amp; Cells (S, 23) & amp; ", '" & amp; Cells (S, 24) & amp; "', '" & amp; Cells (S, 25) & amp; "', '" & amp; Cells (S, 26) _
& "', '" & amp; Cells (S, 27) & amp; "', '" & amp; Cells (S, 28) & amp; "', '" & amp; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related