Hi all,
I am trying to debug this code. I am using a search function to retrieve values from a workbook and return them to multiple textboxes in my userform. So each record is assigned a projectID. Multiple records may have the same ProjectID to a maximum of 4 so there are 4 different sets of textboxes. The code below works but there are some problems:
1. It doesn't return every value
2. the values are returned in the wrong order (it should grab the values and return them in order from top to bottom, currently it has reversed this order)
Any help would be greatly appreciated!
row_number = 1
Do
DoEvents
row_number = row_number
item_in_review2 = Sheets("Permitting Agency Information").Range("A" & row_number)
If item_in_review2 = txtProjectID.Text Then
txtPermitAgencyName1.Text = Sheets("Permitting Agency Information").Range("B" & row_number) ' These values are returned that match the ProjectID (Does not include other sheets as it stands (only Master Project Form))
txtPermitNumber1.Text = Sheets("Permitting Agency Information").Range("C" & row_number)
cmboPermitStatus1.Text = Sheets("Permitting Agency Information").Range("D" & row_number)
txtApplicationDate1.Text = Sheets("Permitting Agency Information").Range("E" & row_number)
End If
Loop Until item_in_review2 = ""
row_number = 1
Do
DoEvents
row_number = row_number + 1
item_in_review3 = Sheets("Permitting Agency Information").Range("A" & row_number)
If item_in_review3 = txtProjectID.Text Then
txtPermitAgencyName2.Text = Sheets("Permitting Agency Information").Range("B" & row_number) ' These values are returned that match the ProjectID (Does not include other sheets as it stands (only Master Project Form))
txtPermitNumber2.Text = Sheets("Permitting Agency Information").Range("C" & row_number)
cmboPermitStatus2.Text = Sheets("Permitting Agency Information").Range("D" & row_number)
txtApplicationDate2.Text = Sheets("Permitting Agency Information").Range("E" & row_number)
End If
Loop Until item_in_review3 = ""
row_number = 1
Do
DoEvents
row_number = row_number + 2
item_in_review4 = Sheets("Permitting Agency Information").Range("A" & row_number)
If item_in_review4 = txtProjectID.Text Then
txtPermitAgencyName3.Text = Sheets("Permitting Agency Information").Range("B" & row_number) ' These values are returned that match the ProjectID (Does not include other sheets as it stands (only Master Project Form))
txtPermitNumber3.Text = Sheets("Permitting Agency Information").Range("C" & row_number)
cmboPermitStatus3.Text = Sheets("Permitting Agency Information").Range("D" & row_number)
txtApplicationDate3.Text = Sheets("Permitting Agency Information").Range("E" & row_number)
End If
Loop Until item_in_review4 = ""
row_number = 1
Do
DoEvents
row_number = row_number + 3
item_in_review5 = Sheets("Permitting Agency Information").Range("A" & row_number)
If item_in_review5 = txtProjectID.Text Then
txtPermitAgencyName4.Text = Sheets("Permitting Agency Information").Range("B" & row_number) ' These values are returned that match the ProjectID (Does not include other sheets as it stands (only Master Project Form))
txtPermitNumber4.Text = Sheets("Permitting Agency Information").Range("C" & row_number)
cmboPermitStatus4.Text = Sheets("Permitting Agency Information").Range("D" & row_number)
txtApplicationDate4.Text = Sheets("Permitting Agency Information").Range("E" & row_number)
End If
Loop Until item_in_review5 = ""
End Sub
Bookmarks