redheadincognito
New Member
- Joined
- Mar 1, 2009
- Messages
- 6
Depsite an extensive amount of time searching through the forums, I find myself still having an issue getting the "next" button on my userform to actually get the next item in the database. I wish it to stop once a match is found, fill out the appropriate textboxes on the userform. Then once the button is pressed again, it should go on to the next. but it goes straight to the msgbox stating there are no further entries.
Now, at this pont, the userform will allready hold the information from row 1 (A3 in this code.) and have autofiltered so that the value of combobox1 are the only visible rows. So could that be my problem? I thought I had it covered in here, but something is not right.
I am still a rookie, and this is my first real attempt at anything worthwhile. (no pro though, I am not making money for my efforts, all for learning and efficency.) I have tried and tried with this should be easy to most code. Any help would be GREATLY appreciated. Thank you in advance.
Private Sub CommandButton7_Click()
Sheet65.Select
Dim rng As Range, cell As Range
iName = UserForm23.ComboBox1.Value
Set rng = ActiveSheet.Range("A3:A500")
For Each cell In rng
iBegin:
' check if row is visible - if so, get it
If cell.EntireRow.Hidden = False Then
' process this row
If cell.Offset(1, 0).Value = iName Then
cell.Offset(1, 0).Select
UserForm23.TextBox2.Value = cell.Offset(0, 1).Value
UserForm23.TextBox4.Value = cell.Offset(0, 5).Value
UserForm23.ComboBox2.Value = cell.Offset(0, 2).Value
UserForm23.ComboBox3.Value = cell.Offset(0, 3).Value
UserForm23.ComboBox4.Value = cell.Offset(0, 3).Value
GoTo iEnd
Else
' check if row is hidden - if so, skip it and return to loop
If cell.EntireRow.Hidden = True Then
cell.Offset(1, 0).Select
Exit For
GoTo iBegin
Else
' Determine end of matches
If cell.Offset(1, 0).Value = "" Then
MsgBox "No further entries found.", vbInformation + vbOKOnly, "Error"
iEnd:
Exit For
End If
End If
End If
End If
Next
End Sub
It may not even be correct, or there may be major errors, but I am learning, and it seems to make logical sense in my head.
Thank you again, sorry for the length.
Dave
Now, at this pont, the userform will allready hold the information from row 1 (A3 in this code.) and have autofiltered so that the value of combobox1 are the only visible rows. So could that be my problem? I thought I had it covered in here, but something is not right.
I am still a rookie, and this is my first real attempt at anything worthwhile. (no pro though, I am not making money for my efforts, all for learning and efficency.) I have tried and tried with this should be easy to most code. Any help would be GREATLY appreciated. Thank you in advance.
Private Sub CommandButton7_Click()
Sheet65.Select
Dim rng As Range, cell As Range
iName = UserForm23.ComboBox1.Value
Set rng = ActiveSheet.Range("A3:A500")
For Each cell In rng
iBegin:
' check if row is visible - if so, get it
If cell.EntireRow.Hidden = False Then
' process this row
If cell.Offset(1, 0).Value = iName Then
cell.Offset(1, 0).Select
UserForm23.TextBox2.Value = cell.Offset(0, 1).Value
UserForm23.TextBox4.Value = cell.Offset(0, 5).Value
UserForm23.ComboBox2.Value = cell.Offset(0, 2).Value
UserForm23.ComboBox3.Value = cell.Offset(0, 3).Value
UserForm23.ComboBox4.Value = cell.Offset(0, 3).Value
GoTo iEnd
Else
' check if row is hidden - if so, skip it and return to loop
If cell.EntireRow.Hidden = True Then
cell.Offset(1, 0).Select
Exit For
GoTo iBegin
Else
' Determine end of matches
If cell.Offset(1, 0).Value = "" Then
MsgBox "No further entries found.", vbInformation + vbOKOnly, "Error"
iEnd:
Exit For
End If
End If
End If
End If
Next
End Sub
It may not even be correct, or there may be major errors, but I am learning, and it seems to make logical sense in my head.
Thank you again, sorry for the length.
Dave