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.
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]