blitz84
03-26-2003, 01:20 PM
I have a seach button that will search excel for whatever is in a certain textbox and return the data it found in another text box. I can get it to return the values from Column "A" but it wont return anything from Column "B". Heres the code for the search button
Private Sub cmdSearch_Click()
Dim c As Range
Dim firstAddress As String
Dim InSheet As Long
Dim i As Integer
For i = 1 To Worksheets.Count 'range your looking in
Worksheets(i).Activate
With Worksheets(i).Columns(1)
Set c = .Find(txtBookCode.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Activate
'Store last sheet that you found something
InSheet = i
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
'Reset first address for the new sheet
firstAddress = ""
End If
End With
Next
'If found
If InSheet > 0 Then
'Return to Worksheet containing last found cell
Worksheets(InSheet).Activate
txtFoundCode.Text = ActiveCell.Offset(0, 0).Value
txtFoundWrap.Text = ActiveCell.Offset(0, 1).Value
Else
MsgBox "Not found"
End If
End Sub
Private Sub cmdSearch_Click()
Dim c As Range
Dim firstAddress As String
Dim InSheet As Long
Dim i As Integer
For i = 1 To Worksheets.Count 'range your looking in
Worksheets(i).Activate
With Worksheets(i).Columns(1)
Set c = .Find(txtBookCode.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Activate
'Store last sheet that you found something
InSheet = i
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
'Reset first address for the new sheet
firstAddress = ""
End If
End With
Next
'If found
If InSheet > 0 Then
'Return to Worksheet containing last found cell
Worksheets(InSheet).Activate
txtFoundCode.Text = ActiveCell.Offset(0, 0).Value
txtFoundWrap.Text = ActiveCell.Offset(0, 1).Value
Else
MsgBox "Not found"
End If
End Sub