Compile Error : Do without Loop but can't figure out where I went wrong

tzexu1610

New Member
Joined
Jan 15, 2018
Messages
15
Hi , guys I've got the code below, but I can't figure out where the compile error is. I thought I have covered all Do's with Loops.

Code:
Sub revampedloop()
    
Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    
    Dim i As Integer
    Dim j As Integer
    Dim a As Long
    Dim b As Long
    Dim myLastRow As Integer


    i = 9  'Start Row
    j = 3   'Z-score column
    
    myLastRow = Range("A" & Rows.Count).End(xlUp).Row
    
'remove error'
    For a = 1 To 2
        On Error Resume Next
        Cells(a, j).SpecialCells(xlCellTypeFormulas, 16).ClearContents
        On Error GoTo 0
        Next a
        
        j = -1
        j = j + 4
        
        Do 'this is for whole sheet loop'
            
'remove the first wave of outlier'
            
            i = 10
            
            Do
                If Cells(i, j - 1).Errors.Item(xlNumberAsText).value = False Then 'result NOT stored as text'
                    If (Abs(Cells(i, j).value) < 3) Then 'not outlier'
                        i = i + 1
                    ElseIf IsEmpty(Cells(i, j)) = True Then 'Skip blank cell'
                        i = i + 1
                    Else
                        Cells(i, j - 1).value = "'" & Cells(i, j - 1).value 'Result is now text'
                        i = 10 'restart at first row
                    End If
                Else
                    i = i + 1
                End If
            Loop Until i > myLastRow 'loop for first column'
            
 '**************************************************************************'
'2nd outlier cleanse'
           
                    j = 2 'starts at the 1st column'


                
                i = 10
                maxrow = 0
                tempmax = 0
                
                'start of max value for 1st column'
   
   Do
        maxrow = 0
        tempmax = 0
   
        Do
                
                If Abs(Cells(i, j + 1).value) < 3 And Abs(Cells(i, j + 1).value) > tempmax Then
                tempmax = Cells(i, j + 1).value
                maxrow = i
                i = i + 1
                
                Else
                
                i = i + 1
                
                End If
                
        Loop Until Cells(i, 1).value = ""
                'end of max value for 1st column'
                i = 10
                
                'start'
                
                If Cells(i, j).Errors.Item(xlNumberAsText).value = False Then 'result is a number'
                
                      tempvarR = Abs(Cells(i, j + 1).value) ' set temporary zscore'
                      tempvarL = Cells(i, j).value 'set temporary result'
                            If tempvarR = tempmax Then
                                       tempvarL = "'" & Cells(i, j).value 'temp result is now a text'
                                                  If tempvarR >= 3 Then 'if zscore still outlier then perma it'
                                                          Cells(i, j + 1).value = tempvarR
                                                          Cells(i, j).value = tempvarL
                                                   Else
                                                   End If
                             Else
                             i = i + 1
                             End If
                
                Else 'result is not a number'
                
                i = i + 1
                
                End If
    
                'stop'
                
          
      j = j + 4
      i = 10
    
 
 Loop Until Cells(9, j + 4).value = ""
'*************************************'
        
        Application.ScreenUpdating = True
        Application.DisplayStatusBar = True
        
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you think all your Do's have complementary Loop's, check all your For's you may be missing a Next, and all your If's you may be missing an End If.
 
Last edited:
Upvote 0
Looked through it. Pretty sure all of them are satisfied. Any other suggestions? D:
If you think all your Do's have complementary Loop's, check all your For's you may be missing a Next, and all your If's you may be missing an End If.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top