Excel Search VBA

kendals

Board Regular
Joined
May 19, 2007
Messages
55
Hi I have the following code below, im not sure how to modify it to make it only search 2 columns of information, how can do this?
thanks
:eek:
Code:
Private Sub CommandButton3_Click()
Dim StrFindWhat As Range
Dim NextCell As Range
Dim WhatToFind As Variant

WhatToFind = Application.InputBox("Please enter the Application or Service you want to search for?", "Search", , 500, 80, , , 2)
If WhatToFind <> "" And Not WhatToFind = False Then
For Each oSheet In ActiveWorkbook.Worksheets
oSheet.Activate
oSheet.[b4].Activate

Set StrFindWhat = Cells.Find(What:=WhatToFind, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not StrFindWhat Is Nothing Then
StrFindWhat.Activate
If MsgBox("Found " & Chr(34) & WhatToFind & Chr(34) & " in " & oSheet.Name & "!" & StrFindWhat.Address, vbOKCancel) = vbCancel Then Exit Sub
On Error Resume Next
While (Not NextCell Is Nothing) And (Not NextCell.Address = StrFindWhat.Address)
Set NextCell = Cells.FindNext(After:=ActiveCell)
If Not NextCell.Address = StrFindWhat.Address Then
NextCell.Activate
If MsgBox("Found " & Chr(34) & WhatToFind & Chr(34) & " in " & oSheet.Name & "!" & NextCell.Address, vbOKCancel) = vbCancel Then Exit Sub
End If
Wend
End If
Set NextCell = Nothing
Set StrFindWhat = Nothing
Next oSheet
End If
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Can anyone help, i just need to change the vba code to just search a range from column a and b.
thanks
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top