Search using cell value

burdie87

Board Regular
Joined
May 25, 2005
Messages
152
Hi Guys & Girls,

I am trying to cobble together a sub to use a cell value in my current workbook to search in a different workbook which may or may not need to be opened before the search can take place. (I have the code below which I have tried to piece together but this is a bit above my skill level.
Any help would be greatly appreciated.
Code:
Private Sub CommandButton36_Click()
Dim WB As Workbook, found As Range

WB = "H:\Machine History File.xls"
Tag = Range("R12:U12")

Set found = WB.Cells.Find(What:=Tag, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Not found Is Nothing Then
    ActiveCell.Offset(0, 1).Value = "ok"
End If

End Sub
 
Yup, you sure can do that! :)

Rich (BB code):
Dim Wb As Workbook, Ws As Worksheet
Dim Rng As Range, R As Range, C As Range

Set Rng = ThisWorkbook.ActiveSheet.Range("R12:U12")

If WorksheetFunction.CountA(Rng) = 0 Then Exit Sub

On Error Resume Next
Set Wb = Workbooks("Machine History File")
On Error GoTo 0
If Wb Is Nothing Then Set Wb = Workbooks.Open("H:\Machine History File.xls")

For Each C In Rng
    For Each Ws In Wb.Worksheets
        Set R = Ws.Cells.Find(C.Value, , xlValues, xlWhole)
        If Not R Is Nothing Then Application.Goto R : Exit Sub
    Next Ws
Next C
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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