PDA

View Full Version : Modify macro to output to Combobox



swaggerbox
11-28-2019, 04:20 AM
I have a macro that searches a textbox for diseases listed in a range (acty sheet column A). Is there a way I can output the results to 1) combo box, 2) listbox, or 3) on the existing sheet. I want three different examples so I know how to deal with them in the future. Attached is the representative sample. Hope someone can help me.



Public Sub T()
Dim sSentence As String
Dim s As Variant
Dim sDict As Variant
Dim last As Long

last = Sheets("Acty").Range("A65536").End(xlUp).Row

sDict = Sheets("Acty").Range("A1:A" & last)

sSentence = Sheets("GUI").TextBox1

For Each s In sDict
If InStr(1, sSentence, Trim$(s), VbCompareMethod.vbTextCompare) > 0 Then
MsgBox s
Else

End If
Next

End Sub

snb
11-28-2019, 06:18 AM
In codemodule of Sheet1:


Sub M_snb()
sn = Sheet1.Cells(1).CurrentRegion
c00 = Sheets("GUI").TextBox1

For j = 1 To UBound(sn)
If InStr(c00, sn(j, 1)) Then c01 = c01 & vbLf & sn(j, 1)
Next

MsgBox c01
End Sub

p45cal
11-28-2019, 10:24 AM
See attached.

swaggerbox
11-29-2019, 03:54 AM
Wow p45cal. You are Heaven-sent. This is exactly what I need. Thanks also snb as always