Hi all,
I'm trying to use the results of a userform combobox search of a second workbook in the userform list box where I can then select one choice and fetch the contents of three columns in the selected row from the second workbook to populate cells on the first workbook.
I'm stuck with trying to get the search string address into RowSource to actually see the cell contents (not the AddressStr) and list them. The results will vary in number (foundNum +1) with each search. I've tried about 20 different ideas but find myself lacking the smarts to sort this out.
Looking at the code further down, have I put the ListBox1.RowSource code in the correct place? Dare I ask what else is wrong?
Below is the line that I cannot sort. Any advice welcome.
Part of the code (PN Search) I've used has no attributes so to the person who wrote it, thanks.
Cheers, Dave
I'm trying to use the results of a userform combobox search of a second workbook in the userform list box where I can then select one choice and fetch the contents of three columns in the selected row from the second workbook to populate cells on the first workbook.
I'm stuck with trying to get the search string address into RowSource to actually see the cell contents (not the AddressStr) and list them. The results will vary in number (foundNum +1) with each search. I've tried about 20 different ideas but find myself lacking the smarts to sort this out.
Looking at the code further down, have I put the ListBox1.RowSource code in the correct place? Dare I ask what else is wrong?
Below is the line that I cannot sort. Any advice welcome.
Code:
ListBox1.RowSource = thisLoc
Code:
Private Sub Userform_Initialize()
With ListBox1
.Clear ' remove existing entries from the listbox
.ColumnCount = 3 'ListBox1.RowSource = rSource.Address(external:=True)
ListIndex = -1
End With
UserForm1.Show
End Sub
Code:
Private Sub CommandButton1_Click()
Dim rSource As Range
Dim oWbSource As Workbook
Dim ws As Worksheet, Found As Range, rngNm As String
Dim myText As String, FirstAddress As String, thisLoc As String
Dim AddressStr As String, foundNum As Integer
'Set Search String
Something = ComboBox1.Value
If UserForm1.ComboBox1.ListIndex <> 1 Then
'Open WB to search
Set SourceWB = Workbooks.Open("C:\Users\oc_txls47\Desktop\Crew docs\Dave Parsell\System Inventory Latest 4-1-14").Worksheets("Sheet1").Range("b5:f45")
For Each ws In ActiveWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(What:=Something, LookIn:=xlValues, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
foundNum = foundNum + 1
rngNm = .Name
AddressStr = AddressStr & .Name & " " & Found.Address & vbCrLf
thisLoc = rngNm & " " & Found.Address
Sheets(rngNm).Select
Range(Found.Address(RowAbsolute:=False, _
ColumnAbsolute:=False)).Select
Set Found = .UsedRange.FindNext(Found)
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
End With
Next ws
If Len(AddressStr) Then
ListBox1.RowSource = thisLoc
Else:
ListBox1.Value = "Unable to find " & Something & " in this workbook."
End If
Exit Sub
End If
End Sub
Cheers, Dave