Hi. I'm trying to find something, somewhere on some worksheet and have got so far but not far enough. I've been having a look around the threads and this code seems to work (in Excel 2000 - on a small test workbook) to find something on the same worksheet and use the value in the next cell to paste back next to the selected cell:-
So far, so good.
But I want to be able to find it on any sheet (it should only occur once but could be anywhere).
So, I tried the following from another thread (just to see if it would display anything):-
Unfortunately I just get the 'can't be found' message.
The other funny thing is that when I F8 step through the code it appears to loop through the For/Next 7 times although there are only 3 worksheets. Not sure if that's significant.
What we are trying to achieve is a single summary sheet of products that updates from many different product category worksheets containing non-contiguous data.
I'm so close I can smell success - but oh so far. A military friend once told me that, "Nearly doesn't count, except in Horse-shoes and hand grenades."
I'm sure someone can help me out.
Many thanks,
Des.
Code:
Sub TestFindCell()
Dim c As Range
Set c = Cells.find(What:=ActiveCell.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False)
MyRow = c.Row 'Just for my reference so I can see what's going on when I step through it.
MyColumn = c.Column 'Ditto
With (Cells(MyRow, MyColumn + 1)) 'Copies then pastes at the original location
.Copy Destination:=Cells(ActiveCell.Row, ActiveCell.Column + 1)
End With
End Sub
But I want to be able to find it on any sheet (it should only occur once but could be anywhere).
So, I tried the following from another thread (just to see if it would display anything):-
Code:
Sub SearchBook2()
Dim ws As Worksheet
Dim sRes As String
Dim Found As Range
For Each ws In ThisWorkbook.Worksheets
Set Found = ws.Cells.find(ActiveCell.Value)
If Not Found Is Nothing Then
sRes = ActiveCell.Value & " found in worksheet " & ws.Name & " cell " & Found.Address
Exit For
End If
Next
If sRes = "" Then sRes = ActiveCell.Value & " can't be found in this workbook"
MsgBox sRes
End Sub
The other funny thing is that when I F8 step through the code it appears to loop through the For/Next 7 times although there are only 3 worksheets. Not sure if that's significant.
What we are trying to achieve is a single summary sheet of products that updates from many different product category worksheets containing non-contiguous data.
I'm so close I can smell success - but oh so far. A military friend once told me that, "Nearly doesn't count, except in Horse-shoes and hand grenades."
I'm sure someone can help me out.
Many thanks,
Des.