I am looking at past questions, but can't figure out how to structure my code. I want to look through the worksheet for a specific test string: ROIC. Once I find it, then I want to copy the cell below it and paste it in another workbook.
Sub Macro1()
' Error handling if it can't find value
On Error GoTo err_chk
' Find value and copy cell under it
Cells.Find(What:="ROIC", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Offset(1, 0).Copy
' Go to new location and paste
Windows("Book2.xls").Activate
Sheets("Sheet2").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
On Error GoTo 0
Exit Sub
' Error handling
err_chk:
If Err.Number = 91 Then
MsgBox "Cannot find the value ROIC on active sheet"
Else
MsgBox Err.Number & ": " & Err.Description
End If
End Sub
Sub FindAndCopy()
Dim ValueToFind As String, fCell As Range
ValueToFind = InputBox("Enter the value to search for.", "Search for . . ")
Set fCell = Cells.Find(ValueToFind, lookat:=xlWhole)
If fCell Is Nothing Then
MsgBox "'" & ValueToFind & "' can not be found in this sheet.", vbInformation, "Search Results"
Else
fCell(2).Copy 'Your paste destination goes here.
End If
Application.CutCopyMode = False
End Sub