VBA - InputBox to select a cell but also store the worksheet as a variable

gmcgough600

New Member
Joined
Nov 21, 2017
Messages
33
Office Version
  1. 365
Hi,

I've got the following code which works but I need a way to also store which workbook the selected cell was on:

VBA Code:
find_cell = Application.InputBox("Select first cell in list of data to find", Default:=Selection.Address, Type:=8).Address

I'm working across multiple sheets (and possibly workbooks), but this code only works if everything is on the same sheet.

Any suggestions? Thanks in advance.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
paste code into a module then run: FindMyWord

Code:
Sub FindMyWord()
Dim vRet
Dim ws As Worksheet

On Error GoTo errFind   'Resume Next

vRet = InputBox("Enter Find Word")
If vRet = "" Then Exit Sub

For Each ws In Sheets
   ws.Activate
  
       Cells.find(What:=vRet, After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate

  MsgBox "found in " & ws.name & ":" & activecell.address
  Exit For
 
resumeFind:
Next
Set ws = Nothing
Exit Sub

errFind:
Resume resumeFind
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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