Today() in a Macro

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
660
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I want todays date Set as a Rng in the following macro:

VBA Code:
 Dim Rng As Range
    
        Set Rng = Today()
        Sheets("BJ's Income").Select
        Set foundRng = Range("A:A").Find(Rng)
        
    'if "Not" Nothing (if its found) then perform code
        If Not (foundRng Is Nothing) Then
            foundRng.Select
            ActiveCell.Offset(11, 0).Select
            Selection.Copy
            ActiveCell.PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False

Thank you.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Today is not a cell or cell range.
In vba you don't use Today you use Date.
You can assign Date to a variable, for example:

VBA Code:
Sub otest()
  Dim foundRng As Range
  Dim dt As Date
  dt = Date
  Sheets("BJ's Income").Select
  Set foundRng = Range("A:A").Find(dt)
  If Not (foundRng Is Nothing) Then
    foundRng.Select
  End If
End Sub

Or directly

VBA Code:
Sub otest2()
  Dim foundRng As Range
  Sheets("BJ's Income").Select
  Set foundRng = Range("A:A").Find(Date)
  If Not (foundRng Is Nothing) Then
    foundRng.Select
  End If
End Sub
 
Upvote 0
Solution
Today is not a cell or cell range.
In vba you don't use Today you use Date.
You can assign Date to a variable, for example:

VBA Code:
Sub otest()
  Dim foundRng As Range
  Dim dt As Date
  dt = Date
  Sheets("BJ's Income").Select
  Set foundRng = Range("A:A").Find(dt)
  If Not (foundRng Is Nothing) Then
    foundRng.Select
  End If
End Sub

Or directly

VBA Code:
Sub otest2()
  Dim foundRng As Range
  Sheets("BJ's Income").Select
  Set foundRng = Range("A:A").Find(Date)
  If Not (foundRng Is Nothing) Then
    foundRng.Select
  End If
End Sub
Thank you.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,632
Messages
6,125,909
Members
449,274
Latest member
mrcsbenson

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