lucky12341
Board Regular
- Joined
- Nov 4, 2005
- Messages
- 121
I need to know if something is possible with the code I am using or is there a way to change the code to do this.
The VBA code listed below searches sheet10 in the A column for whatever I type into txtLocation. I need to know if there is a way to use a checkbox type system to be able to search through multiple sheets (based on selected checkboxes). I know how to implement the If Then Statements but I cannot figure out how to set the range to keep everything working based on the checkboxes.
The VBA code listed below searches sheet10 in the A column for whatever I type into txtLocation. I need to know if there is a way to use a checkbox type system to be able to search through multiple sheets (based on selected checkboxes). I know how to implement the If Then Statements but I cannot figure out how to set the range to keep everything working based on the checkboxes.
Code:
Private Sub cmdLocationFind_Click()
Dim strFind, FirstAddress As String 'what to find
Dim rSearch As Range 'range to search
Set rSearch = Sheet10.Range("a3", Range("a10425").End(xlUp))
strFind = Me.txtLocation.Value 'what to look for
Dim f As Integer
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then 'found it
c.Select
With Me 'load entry to form
.txtPO.Value = c.Offset(0, 1).Value
.txtItemNo.Value = c.Offset(0, 2).Value
.txtPN.Value = c.Offset(0, 3).Value
.txtPcMk.Value = c.Offset(0, 4).Value
.txtDescription.Value = c.Offset(0, 6).Value
.txtHIC.Value = c.Offset(0, 7).Value
.txtOQty.Value = c.Offset(0, 8).Value
.txtCQty.Value = c.Offset(0, 5).Value
.cmdAmend.Enabled = True 'allow amendment or
.cmdDelete.Enabled = True 'allow record deletion
.cmdAdd.Enabled = False 'don't want to duplicate record
.cmdLocationFindAll.Enabled = True
.cmdPOFindAll.Enabled = False
.cmdItemNoFindAll.Enabled = False
.cmdPNFindAll.Enabled = False
.cmdPcMkFindAll.Enabled = False
.cmdDescriptionFindAll.Enabled = False
.cmdHICFindAll.Enabled = False
f = 0
End With
FirstAddress = c.Address
Do
f = f + 1 'count number of matching records
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
If f > 1 Then
MsgBox "There are " & f & " instances of " & strFind
Me.Width = 500
Me.Height = 426.75
End If
Else: MsgBox strFind & " not listed as a Location." 'search failed
End If
End With
End Sub