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

gmcgough600

New Member
Joined
Nov 21, 2017
Messages
32
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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