Home > Software engineering >  Why can't this code normal execution, a great god, please have a look.
Why can't this code normal execution, a great god, please have a look.

Time:11-13

Check the one-to-many and delete duplicate Sub ()
A=Sheets (" sheet1 "). [a1]. CurrentRegion. Rows. Count
B=Sheets (" sheet2 "). [a1]. CurrentRegion. Rows. Count
For I=2 To a
For j=2 To b
If (Sheet1. Cells (I, 2)=Sheet2. Cells (j, 2)) Then
Sheet1. Cells (I, 4)=Sheet2. Cells (j, 4)
Sheet2. Cells (j, 2). Select
Selection. EntireRow. Delete
The Exit For
End the If
Next j
Next I
End Sub

CodePudding user response:

Don't know what my answer touch sensitive word, screenshots send go up,

CodePudding user response:

You is really good, I understand, I used to have a statement, can be normal execution, is this:
Sub delete (same)
A=Sheets (" sheet1 "). [a1]. CurrentRegion. Rows. Count
For I=2 To a
J=I + 6
4: If Application. WorksheetFunction. CountIf ([B1: B2500], the Cells (I, 2)) & gt; 6 Then
Cells (j, 1.) Select
Selection. EntireRow. Delete
A=a - 1
If Application. WorksheetFunction. CountIf ([B1: B2500], the Cells (I, 2)) & gt; 6 Then
GoTo 4
End the If
End the If
Next I
End Sub

This can run normally, I didn't use variables directly for the use area [B1: B2500), my data is not more than 2500 lines,
I replace area with variable now, I will not line, I generally is to use tags, then the manual processing, well,,,,,,,,, actually can realize fine, is a study of the
But still sincerely thank X - I - N, and possibly question, after another problem has been solved perfectly,

I had not learned any vb, I have studied at school assembly, long forgotten, all of my macros are on the Internet to find similar, trying to understand, and then a little bit of change, sometimes by recording, make out, and then change, test error is really pain, this sentence for a few days, I

I again for a short time,

CodePudding user response:

I'm good for!!!!!!!!!!
Check the one-to-many and delete duplicate Sub ()
A=Sheets (" sheet1 "). [a1]. CurrentRegion. Rows. Count
B=Sheets (" sheet2 "). [a1]. CurrentRegion. Rows. Count
For I=2 To a
For j=2 To b
If (Sheet1. Cells (I, 2)=Sheet2. Cells (j, 2)) Then
Sheet1. Cells (I, 4)=Sheet2. Cells (j, 4)
Sheet2. Cells (j, 2) EntireRow. Delete
End the If
Next j
Next I
End Sub


It is ok, the original problem when using the IF the Cells (I, 2), Cells (j, 2), Cells (I, 4) -- -- -- -- -- -- -- -- -- -- - all in the circulation of the IF all the variables in the cell Selection, so an error, I directly to Sheet2. With his eyes closed Cells (j, 2) EntireRow. Delete, unexpectedly is ok,

CodePudding user response:

Incredibly still in the loop for operating cycle collection... A bit speechless
You can try this delete even wrong example look at the actual effect,
 Sub (aa) 
For I=1 To 20
Cells (I, 1)=I
Next I
For I=1 To UsedRange. Rows. Count
If I Mod 2=0 Then Rows (I) Delete
Next I
End Sub

CodePudding user response:

Thank you very much, I today just stumbled on my code is missing, not manual check myself, really can not find, meaning I am finally understand, the problem of or pointer,

CodePudding user response:

reference 1/X - I - n reply:
don't know what my answer touch sensitive word, screenshots send go up,
how do you can send pictures? Very fierce
  •  Tags:  
  • VBA
  • Related