Searching a sheet and displaying on a userform

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
440
Office Version
  1. 365
Platform
  1. Windows
Hi
I use the following code to search for a members surname in a worksheet, and having found it, display a userform to show the details from the row. I have duplicate surnames in the worksheet and I would like to add a spin button to the userform to be able to view duplicate surnames in the userform, in turn.
Is this possible.
thanks

Private Sub SearchForMember2()

Dim FindString As String
Dim rng As Range
Dim Number As Range
Dim SelectedCell As String

FindString = Member.Value
If Trim(FindString) <> "" Then
With Sheets("tmes members").Range("B:B")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng Is Nothing Then
Application.GoTo rng
ActiveCell.Offset(rowOffset:=0, columnOffset:=-1).Select



End If
End With
Else: Exit Sub
End If

FindAMember2.Hide
DisplayMemberDetails
End Sub
 
Thanks for all of your time and effort, much appreciated.
Not sure why it worked in the trial workbook, buts alls well now
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Thanks for all of your time and effort, much appreciated.
Not sure why it worked in the trial workbook, buts alls well now
Good.

It's good practice not to have spaces in worksheet names.

It will always catch you out at some point if you do.
 
Upvote 0
I have followed your advice and removed the spaces from the sheet names.
I have now found another anomoly.
If I search for a member in the first 43rows it all works as expected, but if I search for a member from row 44 onwards, I get the problem shown in the attached screenshot.
Any ideas please
 

Attachments

  • Screenshot_1.jpg
    Screenshot_1.jpg
    56.9 KB · Views: 4
Upvote 0
I have followed your advice and removed the spaces from the sheet names.
I have now found another anomoly.
If I search for a member in the first 43rows it all works as expected, but if I search for a member from row 44 onwards, I get the problem shown in the attached screenshot.
Any ideas please
It's hard to say but at least one row has been found as that code wold not run had that not been the case.

What is in that cell in the first row for that member surname?

Is it anything but text?
 
Upvote 0
I have now done some further testing, and the problem is not the number of rows, it occurs when there is only a single surname, If there are more than 1 member with the same surname it works.
 
Upvote 0
I have now done some further testing, and the problem is not the number of rows, it occurs when there is only a single surname, If there are more than 1 member with the same surname it works.
Are you using the latest code because that was one of the problems that I cured in the latest version.
 
Upvote 0
Sorry for wsting your time, my mistake, I had not changed the code in the
Private Sub subDisplayData(intIndex As Integer) section.
All now working.
Thank you again for your time & effort.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,114
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top