Pulling "Find(What" from another sheet?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Good morning!

I have a simple macro to search a named range (DateColumn) on one sheet (Calendar). As it is currently is the search is for "8/23/21" however I would like the search term to come from a specific cell (B2) on another sheet (SpacerGrid).

Here's the code I started with:

VBA Code:
Sub SearchDate()
   Sheets("Calendar").Select
    Application.Goto Reference:="DateColumn"
    Cells.Find(What:="8/23/21", After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Sheets("Calendar").Select
    Selection.FindNext(After:=ActiveCell).Activate
End Sub

...and here's my unsuccessful attempt to pull the search term from SpacerGrid!B2:

VBA Code:
Sub SearchDate()
   Sheets("Calendar").Select
    Application.Goto Reference:="DateColumn"
    Cells.Find(What:="SpacerGrid!B2", After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Sheets("Calendar").Select
    Selection.FindNext(After:=ActiveCell).Activate
End Sub

Is it possible to target a specific sheet and cell to use as the search term?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This should work (albeit untested):
NB test on a COPY, first!
VBA Code:
Sub SearchDate()
Dim fnd As String

fnd = Sheets("SpacerGrid").Range("B2").Value

   Sheets("Calendar").Select
    Application.Goto Reference:="DateColumn"
    Cells.Find(What:=fnd, After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Sheets("Calendar").Select
    Selection.FindNext(After:=ActiveCell).Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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