Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro outputting everything

Status
Not open for further replies.

wafs

Technical User
Jan 17, 2006
112
US
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
 


Hi,

Put a break in your code at an appropriate place (like the IF statment).

Add a Watch Window to observe the key values.

Step thru the code to observe what's happening.

Skip,

[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
Poultry in motion to pullet for a paltry amount! [tongue]
 
Thanks Skip, I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top