ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Hi,
I currently use a code which looks only in column C but now i need to also be able to look in column D
I though that we could use the Option Buttons for selecting which column to use.
Something like,
If Option Button 1 Then look in column C
If Option Button 2 Then look in column D
Here is the code i think you need.
Many Thanks.
I currently use a code which looks only in column C but now i need to also be able to look in column D
I though that we could use the Option Buttons for selecting which column to use.
Something like,
If Option Button 1 Then look in column C
If Option Button 2 Then look in column D
Here is the code i think you need.
Many Thanks.
Rich (BB code):
Private Sub TextBoxSearch_Change()
Dim r As Range, f As Range, cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("POSTAGE")
sh.Select
With ListBoxSearch
.Clear
.ColumnCount = 2
.ColumnWidths = "100;0"
If TextBoxSearch.Value = "" Then Exit Sub
Set r = Range("C9", Range("C" & Rows.Count).End(xlUp))
Set f = r.Find(TextBoxSearch.Value, LookIn:=xlValues, LookAt:=xlPart)
If Not f Is Nothing Then
cell = f.Address
Do
added = False
For i = 0 To .ListCount - 1
Select Case StrComp(.List(i), f.Value, vbTextCompare)
Case 0, 1
.AddItem f.Value, i
.List(i, 1) = f.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Row
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
TextBoxSearch = UCase(TextBoxSearch)
.TopIndex = 0
Else
MsgBox "NO ITEM WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET ITEM SEARCH"
TextBoxSearch.Value = ""
TextBoxSearch.SetFocus
End If
End With
End Sub