If Range("A1")

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

when my macro is run I want to check the date formatted as yyyy-mm-dd in cell A1

If A1 = TODAY()-1 then A1 = TODAY()
if A1 = TODAY() then A1 =TODAY()+1

code I have at the moment is...
Code:
Sub Clear

Range("A1").FormulaR1C1 = "=TODAY()+1"
how can this bit of code be changed to add in my 'if' conditions above?

many thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try

Code:
With Range("A1")
    If .Value = Date - 1 Then
        .Formula = "=TODAY()"
    ElseIf .Value = Date Then
        .Formula = "=TODAY()+1"
    End If
End With
 
Upvote 0
Or if you want to retain the formula then for example:

Code:
If Range("A1").Formula = "=TODAY()-1" Then
  Range("A1").Formula = "=TODAY()"
Else
  Range("A1").Formula = "=TODAY()+1"
ENd If
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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