Home > Software engineering >  Turn a for loop statement, the code written for
Turn a for loop statement, the code written for

Time:09-18

Private Sub Worksheet_Change (ByVal Target As Range)
Dim x As Integer
Dim y As Integer
X=Target. Row
If Target. Count & gt; 1 Then the Exit Sub
If the Target. The Column=2 Then
For y=1 To x - 1
If the Range (" by ")=Range (bx) Then
Application. Researched. Speak "bar code duplication, please check the barcode"
MsgBox (" barcode repeat, please check the bar code ")
Range (" B "& amp; X). The Clear: Range (" B "& amp; X). Select
Next y
The Else: Target. Offset (, 1). Select
End the If
If the Range (" B "& amp; X) & lt;> "" And Range (" C" & amp; X) & lt;> "" And Range (" B" & amp; X) & lt;> Range (" C "& amp; X) Then
Application. Researched. Speak "character length or content is not consistent, please check the barcode"
MsgBox (" character length or content is not consistent, please check the barcode ")
Range (" B "& amp; X). The Clear: Range (" C "& amp; X). The Clear: Range (" B "& amp; X). Select
If the Target. The Column=3 Then Target. Offset (1, 1). Select
End the If
End Sub

CodePudding user response:

F5 to run, if you can run, also can get the right results, right,

CodePudding user response:

Don't superstitious books, examination questions, teachers, reply;
CPU to superstitions, compiler, debugger, run results,
And please combine "the blind man touched the sun" and "boat out to sea must carry only a compass," try to understand,
Any theory, authority, according to legend, the truth, and the standard, explain, imagination, knowledge... Is not in my eyes!

CodePudding user response:

Code function at the end of the day is not others to help you see or interpretation or comment; But by myself calm down and take a long enough time and energy to do it yourself step or set a breakpoint or step to perform to a certain intermediate result shows or written to the log file analysis step by step,
Remind: cow x teacher cannot replace the student understand and use the toilet!
Single step debugging and set breakpoint debugging is one of the programmers must master the skills,

All commented On the Error Resume Next statement, running in the VBA IDE,
The error and then click the debugging, the cursor will stop error in the statement,
Or
In doubt may have a logical error statements in advance to set breakpoints, run through the breakpoint interrupt,

At this point can be used in the immediate window
? The variable name
Or
? The function name () function parameter
Or
Process (parameters)
Auxiliary debugging,

CodePudding user response:

Who knows, you are the vba, is related to your excel document structure, light on how do you know code, such as your a b c three columns, there is such a deposit, there is no bar code, etc.,
Under the upstairs said, put into operation is the most simple way to know line not line,

CodePudding user response:

Probably looked at it and application process of the order has a problem, IF statements in the FOR, should be IF the end of the first to end the FOR, you did not end after the end of the first FOR the IF, typical process logic errors,

CodePudding user response:

There are a lot of wrong a see
  •  Tags:  
  • VBA
  • Related