cokingtins1
06-05-2017, 09:36 AM
When I run the code, the loop does not iterate to the outer 2 loops ("jrownumber" and "jrow"). Rather, it keeps iterating through "jrowprice" endlessly. I don't know if the "Step" keyword has anything to do with it but could someone please help?
Sub PriceMatch()
Dim LastRow As Long
Dim sht As Worksheet
Dim jrow As Integer
Dim jrowprice As Integer
Dim jrowNumber As Integer
Dim DirectingFileName As String
Dim a As Integer
Dim b As Integer
Dim c As Integer
Set sht = ThisWorkbook.Worksheets("Pivot Tables")
DirectingFileName = ActiveWorkbook.Name
LastRow = sht.Cells(sht.Rows.Count, "C").End(xlUp).Row
For jrow = 2 To 5000
For jrowNumber = 3 To LastRow Step 2
For jrowprice = 2 To LastRow Step 2
If Workbooks(DirectingFileName).Sheets("Stock Net").Cells(jrow, 5).Value = Workbooks(DirectingFileName).Sheets("Pivot Tables").Cells(jrowNumber, 3).Value Then
Workbooks(DirectingFileName).Sheets("Stock Net").Cells(jrow, 8).Value = Workbooks(DirectingFileName).Sheets("Pivot Tables").Cells(jrowprice, 3).Value
Else
Workbooks(DirectingFileName).Sheets("Stock Net").Cells(jrow, 8).Value = ""
End If
Next jrowprice
Next jrowNumber
Next jrow
End Sub
Sub PriceMatch()
Dim LastRow As Long
Dim sht As Worksheet
Dim jrow As Integer
Dim jrowprice As Integer
Dim jrowNumber As Integer
Dim DirectingFileName As String
Dim a As Integer
Dim b As Integer
Dim c As Integer
Set sht = ThisWorkbook.Worksheets("Pivot Tables")
DirectingFileName = ActiveWorkbook.Name
LastRow = sht.Cells(sht.Rows.Count, "C").End(xlUp).Row
For jrow = 2 To 5000
For jrowNumber = 3 To LastRow Step 2
For jrowprice = 2 To LastRow Step 2
If Workbooks(DirectingFileName).Sheets("Stock Net").Cells(jrow, 5).Value = Workbooks(DirectingFileName).Sheets("Pivot Tables").Cells(jrowNumber, 3).Value Then
Workbooks(DirectingFileName).Sheets("Stock Net").Cells(jrow, 8).Value = Workbooks(DirectingFileName).Sheets("Pivot Tables").Cells(jrowprice, 3).Value
Else
Workbooks(DirectingFileName).Sheets("Stock Net").Cells(jrow, 8).Value = ""
End If
Next jrowprice
Next jrowNumber
Next jrow
End Sub