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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code not looping

Status
Not open for further replies.

wafs

Technical User
Jan 17, 2006
112
US
Here is a code that I created and I need it to run through the entire code before it loops. I need the code to look at all the ID numbers before it increments and loops. Any suggestions?

Sub copyinfo_to_main_page()
'
' copyinfo Macro
' Macro recorded 4/7/2006 by Wendy Smith
'
Dim Cellstart As Integer
Dim p As Integer
Dim x As Integer
Dim n As String 'counting variable
Dim m As String
Dim TestRange As String 'to process
Dim TestRange2 As String 'part number
Dim TestRange3 As String 'id number
Dim sh As String 'source sheet
Dim destsh As String 'destination sheet
Dim reportlocation As String
Dim output(1 To 14) As String
Dim strvar1 As String
Dim vRet As Variant
Dim myrange As Range
Dim rsearch As Range

Cellstart = 2 'starting point of source sheet
p = 0
strvar1 = "X"

sh = "data" 'work sheet where the part info is kept
destsh = "Main Page" 'work sheet where part info is broken out

'Clear out old Data and unhide rows
Sheets("Main Page").Select
Sheets(destsh).Range("A2:h400").Select
Selection.ClearContents

'Retreive data from source sheet
n = Cellstart

TestRange = "E" + n 'to process source sheet
TestRange2 = "B" + n 'part # source sheet
TestRange3 = "A" + n 'ID number source sheet
output(1) = "A" + n 'part number
output(2) = Sheets(destsh).Range(output(1)).Value
output(3) = "C1" 'WASH
output(4) = Sheets(destsh).Range(output(3)).Value
output(9) = "D1" 't/p
output(10) = Sheets(destsh).Range(output(9)).Value
output(5) = "E1" 'Roll
output(6) = Sheets(destsh).Range(output(5)).Value
output(7) = "F1" 'HT
output(8) = Sheets(destsh).Range(output(7)).Value
output(11) = "G1" 'ship
output(12) = Sheets(destsh).Range(output(11)).Value
output(13) = "B" + n 'ID Number
output(14) = Sheets(destsh).Range(output(13)).Value

'Output into destination sheet

Sheets("data").Select
Range("A1:A400").AdvancedFilter xlFilterInPlace, CriteriaRange:=Range("A1:A400"), Unique:=True
Columns("A:A").Select
Selection.Copy
Sheets("Main Page").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("data").ShowAllData
Do
Set myrange = Sheets(sh).Range(TestRange3)
Set rsearch = Sheets(destsh).Range(output(13))
If myrange = rsearch Then
p = p + 1
m = p + 1
vRet = Application.WorksheetFunction.VLookup(myrange, Worksheets("data").Range("A2:G300"), 2, False)
reportlocation = "A" + m 'partnumber
Sheets(destsh).Range(reportlocation) = vRet
reportlocation = "C" + m 'X WSH
Sheets(destsh).Range(reportlocation) = strvar1
reportlocation = "E" + m 'X ROLL
Sheets(destsh).Range(reportlocation) = strvar1
reportlocation = "D" + m 'X TP
Sheets(destsh).Range(reportlocation) = strvar1
reportlocation = "F" + m 'X HT
Sheets(destsh).Range(reportlocation) = strvar1
reportlocation = "G" + m 'X SHIP
Sheets(destsh).Range(reportlocation) = strvar1
End If
n = n + 1
TestRange3 = "A" + n
TestRange = "E" + n
output(1) = "A" + n
output(13) = "B" + n
Loop Until Sheets(destsh).Range(output(13)) = ""
End Sub
 


Wendy,

Have you set up Breaks and stepped thru your code to observe the test values in each of your if statements?

If so, what did you observe?



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]
 
It runs through the if statements and goes to the endif when the conditions are met, but the output is not coming out right because I need to have some condition statements for each output. I have five stages the ID number goes through and will need to put an X in the stage where it have been scanned. If I do if statements for all five stages, then the X does not print out on the first line with the ID number, it creates a second line. This is where my problem lines and can't figure out how to get it to work. The code prints an X in every stage, not just the ones it was scanned.

Part Number IDNumber WSH TP ROLL HT Ship
11588715 1428 X X
 


well then, it looks to me like m is getting incrimented incorrectly. Have you checked that?

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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top