Pulling "Find(What" from another sheet?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
278
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

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,)

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,883
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,960
Messages
5,767,336
Members
425,404
Latest member
Bairkus

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
Top