Link to home
Start Free TrialLog in
Avatar of Nancy Therrien
Nancy TherrienFlag for Canada

asked on

For Next Loop, not working

Good Afternoon,
I'm trying to compare data from an Excel Sheets, I have to compare rows with each other.
My data is like :
1 aaaaaaa 19.5  15          louis
2 aaaaaaa  19.5               louis
2 aaaaaaa  19.5 15 a      louis
3 aaaaaaa  19.5               louis

I need to verify that all columns for each row are equal to the rows above.  Here is my code and it is not working.
Can you please help me.
If I don't take care of the 3rd columns it was doing good.

It always give me a NExt error or else without if

Thanks in advance.

dim i as Integer  ' row 6 to end
Dim j As Integer   ' columns F to U
   
   For i = lastrow To 6 Step -1
    
        If Cells(i, 2) = Cells(i - 1, 2) And Cells(i, 6) = Cells(i - 1, 6) Then
                 
		If Cells(i - 1, 23) = Cells(i, 23) Then
    
			For j = 6 To 22 Step 1
                    		If Cells(i, j) = Cells(i - 1, j) Then
  '  			Next j
                      
                      	Cells(i - 1, 1) = Cells(i - 1, 1) + Cells(i, 1)
                      	Rows(i).Delete Shift:=xlUp
            
                Else
                    
                End If
        Else                          ' put color  'met la ligne en couleur
                Rows(i).Select
                
        	        With Selection.Interior
                	 .Pattern = xlSolid
                    	.PatternColorIndex = xlAutomatic
                    	.Color = 65535
                    	.TintAndShade = 0
                    	.PatternTintAndShade = 0
                	End With
         End If
        
        
        
    Next i

Open in new window

Avatar of Norie
Norie

Nancy

This will compile but I can't tell if it'll do what you want without sample before/after data.
Dim i As Integer  ' row 6 to end
Dim j As Integer   ' columns F to U
Dim lastrow As Long

    For i = lastrow To 6 Step -1

        If Cells(i, 2) = Cells(i - 1, 2) And Cells(i, 6) = Cells(i - 1, 6) Then

            If Cells(i - 1, 23) = Cells(i, 23) Then

                For j = 6 To 22 Step 1
                    If Cells(i, j) = Cells(i - 1, j) Then
                        '                    Next j

                        Cells(i - 1, 1) = Cells(i - 1, 1) + Cells(i, 1)
                        Rows(i).Delete Shift:=xlUp

                    Else                          ' put color  'met la ligne en couleur
                        Rows(i).Select

                        With Selection.Interior
                            .Pattern = xlSolid
                            .PatternColorIndex = xlAutomatic
                            .Color = 65535
                            .TintAndShade = 0
                            .PatternTintAndShade = 0
                        End With
                    End If
                Next j
            End If
        End If
    Next i

Open in new window

please post a representative sample workbook
Avatar of Nancy Therrien

ASKER

Here is a sample workbook.

Thanks,
lcv_m03-1114-00-test.xlsm
Is your posted code in one of the modules in the workbook you posted?
Hello,  In module TestNancy, and it is called Test1()

Thanks
I see a Test1() in Module2, but not in TestNancy
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello,
Thanks for helping, it is working great now.
I really appreciated your help.

for the color thing it was just to mark those which are almost identical, the one which the difference is in the S-T or Laser columns.

I will take that off.

Thanks again.
Nancy
Good Morning,

Just for my personnal information and formation.
How this line is working :   boolCellDataIsSame = True
is that true by default ?

Thanks
Nancy
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial