The following code works, except that it seems to ignore the if statement and copies over all part numbers. Can someone help me with my output, there is something missing or written wrong that I'm not seeing. I want the macro to go through last days shipped (AF) and bring over any part number (A) that has not been shipped in over 30 days.
Any help would be greatly appreciated.
Sub Over_30_Days()
Dim reportlocation As String
Dim destsh As String
Dim output(1 To 5) As String
Dim sh As String
Dim i As String
Dim lastrow As Integer
Dim z As Integer
Dim x As Integer
Dim TestRange As String
Dim TestRange2 As String
Dim TestRange3 As String
Dim parts As String
Dim m As String ' counting variable
Dim n As String 'counting variable
Dim v As String
Dim y As Integer
Dim cellstart As String
cellstart = 3
parts = 0
sh = "Daily"
destsh = "Over_30_Days"
'turn off screen updating
Application.ScreenUpdating = False
'Build over 30 sheet
lastrow = Range("A5000").End(xlUp).Row
For z = 1 To lastrow
'Get data from rows
i = cellstart
n = cellstart
TestRange = "AF" + i
TestRange2 = "AE" + i
For x = cellstart To lastrow
If Sheets(sh).Range(TestRange) > 30 And Sheets(sh).Range(TestRange2) <> 0 Then
TestRange = "AF" + i
TestRange3 = TestRange
TestRange2 = "AE" + i
TestRange4 = TestRange2
Else
End If
parts = parts + 1
'Part Number 'HERE IS WHERE MY OUTPUT STARTS
output(1) = "A" + n
output(2) = Sheets(sh).Range(output(1)).Value
'Output ' HERE IS MY OUTPUT REQUEST, WHAT IS WRONG THAT IT MOVES OVER ALL PART NUMBERS.
m = parts + 2
reportlocation = "A" + n
Sheets(destsh).Range(reportlocation) = output(2)
n = n + 1
TestRange3 = Selection.Address
i = i + 1
TestRange = "AF" + i
TestRange2 = "AE" + i
Next
cellstart = lastrow + 2
parts = parts + 1
Next
'Turn off screen updating
Application.ScreenUpdating = True
End Sub
Any help would be greatly appreciated.
Sub Over_30_Days()
Dim reportlocation As String
Dim destsh As String
Dim output(1 To 5) As String
Dim sh As String
Dim i As String
Dim lastrow As Integer
Dim z As Integer
Dim x As Integer
Dim TestRange As String
Dim TestRange2 As String
Dim TestRange3 As String
Dim parts As String
Dim m As String ' counting variable
Dim n As String 'counting variable
Dim v As String
Dim y As Integer
Dim cellstart As String
cellstart = 3
parts = 0
sh = "Daily"
destsh = "Over_30_Days"
'turn off screen updating
Application.ScreenUpdating = False
'Build over 30 sheet
lastrow = Range("A5000").End(xlUp).Row
For z = 1 To lastrow
'Get data from rows
i = cellstart
n = cellstart
TestRange = "AF" + i
TestRange2 = "AE" + i
For x = cellstart To lastrow
If Sheets(sh).Range(TestRange) > 30 And Sheets(sh).Range(TestRange2) <> 0 Then
TestRange = "AF" + i
TestRange3 = TestRange
TestRange2 = "AE" + i
TestRange4 = TestRange2
Else
End If
parts = parts + 1
'Part Number 'HERE IS WHERE MY OUTPUT STARTS
output(1) = "A" + n
output(2) = Sheets(sh).Range(output(1)).Value
'Output ' HERE IS MY OUTPUT REQUEST, WHAT IS WRONG THAT IT MOVES OVER ALL PART NUMBERS.
m = parts + 2
reportlocation = "A" + n
Sheets(destsh).Range(reportlocation) = output(2)
n = n + 1
TestRange3 = Selection.Address
i = i + 1
TestRange = "AF" + i
TestRange2 = "AE" + i
Next
cellstart = lastrow + 2
parts = parts + 1
Next
'Turn off screen updating
Application.ScreenUpdating = True
End Sub