Hi AlphaFrog,
Thanks for coming back again.
It might be easier to see from the files I _..
_ … uploaded ( as .xlsb to fit in, but should be saved as .xlsm for all codes to work )
or
_. … gave the file share site ( box.net ) link to … File Share Link again: https://app.box.com/s/fpztob9pcp92fl6hh81zgpzumw9ntcp0
The file is a bit big and messy as I have been working and adding to it for a couple of years now…..and currently I am experimenting with your search codes. I am probably not doing things the most efficiently as I am experimenting a lot just now_...
All my codes would need about 20 post to fit them all in !!! ..
_......
But here goes, the bits relevant to the current issues.. .. my current versions are something like this:
I have two UserForms, (ufResults and UFrog) , which I treat as Classes, ( as I was reading up and that seemed like a good idea ). So in a normal module, “Globies” I have this:
Public fm As ufResults
Public fmSrch As UFrog ' AlphaFrog https://www.excelforum.com/excel-programming-vba-macros/1186516-smarter-search-process.html#post4660761
In “Sheet1” Worksheet code module of my main File I have , amongst a lot of other stuff , a Worksheet_SelectionChange code, part of which currently causes your UserForm to come up when I select cell G1 . This works simply because cell G1 has this value in it “Gruppieren Food Group” _...... In the Worksheet_SelectionChange code a section looks like this:
ElseIf InStr(1, Target.Value, "Gruppieren", vbBinaryCompare) > 0 Or InStr(1, Target.Value, "Food Group", vbBinaryCompare) > 0 Then
Set fmSrch = New UFrog
fmSrch.Show vbModeless ' False ' modal:=vbModeless, so can do other things
Else
The rest that is relevant is really just my current adaptations of your code as I explained in Post #8. ( There is probably a few redundant bits in it, as I am still experimenting with things, hence my general questions… )
Private Sub UserForm_Initialize()
Me.Frame2.Enabled = False
Me.OptionButton3.Enabled = False
Me.OptionButton4.Enabled = False
Me.OptionButton5.Enabled = False
With Me.ListBox1
.ColumnCount = 3 'Row number????, Name, Kcal
.ColumnWidths = "20;130;40"
End With
End Sub
Private Sub TextBox1_Change() 'Find
Dim FirstFound As String
Me.ListBox1.Clear
Me.Frame2.Enabled = False
Me.OptionButton3.Enabled = False
Me.OptionButton4.Enabled = False
Me.OptionButton5.Enabled = False
Me.OptionButton3.Value = False
Me.OptionButton4.Value = False
Me.OptionButton5.Value = False
Dim rngSearch As Range: Set rngSearch = Worksheets("Sheet1").Range("G71:G17221")
If Me.TextBox1.Value <> "" Then
Dim Found As Range: Set Found = rngSearch.Find(what:="*" & Me.TextBox1.Text & "*", After:=rngSearch.Item(1), LookIn:=xlFormulas, Lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
If Not Found Is Nothing Then
FirstFound = Found.Address
Do
With Me.ListBox1
.AddItem Found.Row 'Row number
.List(.ListCount - 1, 1) = Found.Value 'Name
.List(.ListCount - 1, 2) = Found.Offset(0, 1).Value 'Kcal
End With
Set Found = rngSearch.FindNext(After:=Found)
Loop Until Found.Address = FirstFound
End If
End If
End Sub
Private Sub ListBox1_Click()
Me.Frame2.Enabled = True
Me.OptionButton3.Enabled = True
Me.OptionButton4.Enabled = True
Me.OptionButton5.Enabled = True
Select Case Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
Case "Yes": Me.OptionButton3 = True
Case "No": Me.OptionButton4 = True
Case "Call": Me.OptionButton5 = True
Case Else: Me.OptionButton3 = False: Me.OptionButton4 = False: Me.OptionButton5 = False
End Select
End Sub
Private Sub OptionButton3_Click() 'Yes 'Me.ListBox1.List(Me.ListBox1.ListIndex, 2) = "Yes"
ActiveWindow.Panes(3).Activate ' Typically I have an upper and lower pane. the lower is where most things go on, but I like to keep the headings viewable in pane 1
Worksheets("Sheet1").Range("G" & Me.ListBox1.Value).Select ' Because Evants are enabled the selection cause a code to spring in and open the 50 row section ' Value = "Yes"
Let Application.EnableEvents = False ' The following is just mucking about to try to get all the section viewable
Worksheets("Sheet1").Range("G" & Me.ListBox1.Value + 20).Select 'Value = "No"
Worksheets("Sheet1").Range("G" & Me.ListBox1.Value).Select 'Value = "No"
Let Application.EnableEvents = True
End Sub
Private Sub OptionButton4_Click() 'No
'Me.ListBox1.List(Me.ListBox1.ListIndex, 2) = "No"
Let Application.EnableEvents = False ' Because this is false, the following does not open the selected 50 row section
ActiveWindow.Panes(3).Activate
Worksheets("Sheet1").Range("F" & Me.ListBox1.Value + 20).Select 'Value = "No"
Worksheets("Sheet1").Range("F" & Me.ListBox1.Value).Select 'Value = "No"
Let Application.EnableEvents = True
End Sub
Private Sub OptionButton5_Click() 'Call Close . This code section simpply allows mme to call a code to close the current 50 row section
Me.ListBox1.List(Me.ListBox1.ListIndex, 2) = "Close" ' "Call"
Application.EnableEvents = False
Call Tabelle2.OpenClseSectionPrdFnd((Me.ListBox1.Value - 50), False) ' -50 as value required is top row, - Me.ListBox1.Value appears to be .AddItem Found.Row 'Row number
Application.EnableEvents = True
'Range("D" & Me.ListBox1.Value).Value = "Call"
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
With those codes, if you hit cell G1, and then write in _ “jog” _ in _ “Search for Food Group” _ box, then you see this
Post_17.JPG http://imgur.com/0Eo97JK
Post_17.JPG
Currently I am just not 100% clear how the three lines
.AddItem Found.Row 'Row number
.List(.ListCount - 1, 1) = Found.Value 'Name
.List(.ListCount - 1, 2) = Found.Offset(0, 1).Value 'Kcal
relate to those three seen columns in the List Box. Mostly it is that first _ number: _ which looks weird/ new to me. ( In my other userForm I assign an Array to the list box, and I do not see any first column with funny numbers in it). I can see where the second two columns are coming from. And I am guessing that somewhere a list of the _ .Added _ is held, and when you click on the relavent word, then you get given the _ .Added _ thing ( row number in this case ) via the _ .Value on the ListBox
I guess I am a bit confused with
_ ListBox.Value
and
_ Listbox.List(x, y )
and
_ what that first _ Number: _ has got to do with anything
Alan
Bookmarks