For Loop not entering into body of loop

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am having trouble with a For Loop. Everything above the For RowLoop1 = G to I line appears to be working well. I have been running it line by line with F8. At the line For RowLoop1 = G to I the code proceeds to go directly to the line K = K-1. I am not sure why the script is not entering into the body of this For loop. Any ideas would be very much appreciated.

Code:
[/COLOR]Sub TRENDSHEET()



Dim wsPA As Worksheet
Dim wsTA As Worksheet
Dim PA As Workbook
Dim TA As Workbook
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Dim F As Integer
Dim G As Integer
Dim H As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim RowLoop1 As Long
Dim AA As Range
Dim DD As Range


Set TA = Workbooks("COMM_TREND.xls")
Set PA = Workbooks("COMM_PA.xls")


For Each wsPA In PA.Worksheets


Set wsTA = TA.Worksheets(wsPA.Name)


wsTA.Activate
Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents


wsPA.Activate


A = wsPA.Cells(Rows.Count, "A").End(xlUp).Row


    Do Until A = 2
      
        If wsPA.Cells(A, "E").Value > Application.Large(wsPA.Cells((A - 10), "E").Resize(21), 2) Then
       
        Set AA = wsPA.Cells(A, "E")
        Set DD = wsPA.Cells(A, "A")
        G = AA.Row
        H = wsPA.Cells(A, "A").Row
    
        wsTA.Activate
        
        Range("A1").Select
        Selection.End(xlDown).Offset(1, 0).Select
        Selection.Value = "ACTIVE"
            
        Range("A1").Select
        Selection.End(xlDown).Offset(0, 1).Select
        Selection.Value = DD.Value
        
        Range("A1").End(xlDown).Offset(0, 2).Select
        Selection.Value = AA.Value
       
        E = A
    
        K = E - 10
    Do Until K = 2
                      
        I = 2
                      
            
                For RowLoop1 = G To I
        
                H = wsPA.Cells(E, "A").Row
                B = (wsPA.Cells(K, "E").Value - wsPA.Cells(RowLoop1, "E").Value) / (wsPA.Cells(K, "A").Value -                                        wsPA.Cells(RowLoop1, "A").Value)
                C = wsPA.Range(wsPA.Cells(K, "A"), wsPA.Cells(RowLoop1, "A")).Rows.Count
                I = (wsPA.Cells(K, "E").Value - wsPA.Cells(RowLoop1, "E").Value)
        
                F = RowLoop1 - (RowLoop1 - H)
            
                J = wsPA.Range(wsPA.Cells(H, "A").Value - wsPA.Cells(RowLoop1, "A").Value).Rows.Count
            
                If wsPA.Cells(H, "E").Value > AA.Value + (B * F) And F < C + 10 Then
                
               
                ElseIf wsPA.Cells(H, "E").Value > AA.Value + (B * F) And F > C + 10 Then
                
                wsTA.Range("A1").End(xlDown).Offset(1, 0).Select
                Selection.Value = "ACTIVE"
                
                wsPA.Cells(H, "A").Value.Copy
                wsTA.Range("A1").End(xlDown).Offset(0, 1).Select
                Selection.Paste PasteSpecial:=xlValues
                
                AA.Value.Copy
                wsTA.Range("A1").End(xlDown).Offset(0, 2).Select
                Selection.Paste PasteSpecial:=xlValues
                
                wsPA.Cells(K, "A").Value.Copy
                wsTA.Range("A1").End(xlDown).Offset(0, 3).Select
                Selection.Paste PasteSpecial:=xlValues
                
                wsPA.Cells(K, "E").Value.Copy
                wsTA.Range("A1").End(xlDown).Offset(0, 4).Select
                Selection.Paste PasteSpecial:=xlValues
                
                wsTA.Range("A1").End(xlDown).Offset(0, 5).Value = C
                
                wsTA.Range("A1").End(xlDown).Offset(0, 6).Value = I
                
                wsTA.Range("A1").End(xlDown).Offset(0, 7).Value = B
                
                wsTA.Range("A1").End(xlDown).Offset(0, 8).Select
                Selection.Paste PasteSpecial:=xlValues
                wsPA.Cells(H, "A").Value.Copy
                wsTA.Range("A1").End(xlDown).Offset(0, 9).Select
                Selection.Paste PasteSpecial:=xlValues
               
                ElseIf wsPA.Cells(H, "E").Value < AA.Value + (B * F) Then
                
                End If
    
        Next RowLoop1
        
        K = K - 1
        
  Loop
        
        Else
            A = A - 1
        End If
    
  Loop
        
  Next wsPA
 


End Sub


[COLOR=#333333]
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
It looks very likely that G will be greater than I in which case the loop would never run.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
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