adding a formula to VBA code

James__S

Active Member
Joined
Jan 26, 2014
Messages
332
I have the following code which works plus a formula in cell range G5:G123....how do i add the the formula to the VBA code please

Formula =IF(F5<>"".F5< today () +3 )<today()+3)


Code:
Private Sub Workbook_Open()
For Each cell In Range("F5:F19")
If cell.Value < Date + 3 And cell.Value <> "" Then
cell.Interior.Color = 3
cell.Font.ColorIndex = 2
cell.Font.Bold = True
End If
Next
End Sub

<today(),"send reminder","")
<today()+3)
<today(),"send reminder","")
<today()+3)<today()+3)
<today()+3)

Also instead of having the code update when book opens could it have a Commandbutton so it can be updated anytime

Thanks</today()+3)
</today()+3)<today()+3)
</today(),"send></today()+3)
</today(),"send></today()+3)
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
In what way do you want to "add the formula to the VBA code"? If you want to put it in a cell use the macro recorder while entering it manually to get the VBA syntax.
 
Upvote 0
This would be the code that would go to your Module ( Goto VB Screen > Insert > Module)

Also remember to delete the existing code from Thisworkbook.

Code:
Private Sub Data_Format_Formulas()
For Each cell In Range("F5:F19")
    If cell.Value < Date + 3 And cell.Value <> "" Then
        cell.Interior.Color = 3
        cell.Font.ColorIndex = 2
        cell.Font.Bold = True
    End If
Next
[COLOR=#0000cd]Range("G5:G123").Formula = "=IF(F5<>"""",F5< today () +3 ) "[/COLOR]
End Sub

Your Formula =IF(F5<>"".F5< today () +3 )<today()+3)
, i dont think there should be a dot, it should be comma... Please double check.. My code includes the formula from G5 to G123

Next, you can insert a shape, right click , assign macros.. </today()+3)
 
Upvote 0
Thanks D

the formula i posted for some reason would not show up so i threw in spaces etc..etc..just to get it into the message

Thanks for the VBA code
 
Last edited:
Upvote 0
I get an error in the code,,,,the following is highlighted Yellow



Range("G5:G123").Formula = "=IF(F5<>"""",F5< today () +3 ) "
 
Upvote 0
The formula which you posted is not correct.. what are you trying to achieve in G5 ?
 
Upvote 0
Just Guessing..

Range("G5:G123").Formula = "=IF(F5<>"""",F5,today()+3)"
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,783
Members
448,992
Latest member
prabhuk279

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