Inserting formula with vba into created column

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
184
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am trying to have vba automatically place a formula in a range of cells to determine if the training date in the column beside it will be valid for the entire year. I cannot get the formula to paste into the new column.

'Dim lastRow as Long
'lastRow = Worksheets("New Year").range("c" & rows.count).End(xlUp).Row'
'Worksheets("New Year").range("J3:J" & lastRow).NumberFormat = "mm/dd/yyyy"
'Worksheets("New Year").range("J3:J" & lastRow).Formula = "=If(G3>12/31/2019,G3,If(G3=""COMPLETED"",""COMPLETED"","" "")"

Why does this not insert like the other formulas I have in the worksheet?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Does the formula work if you type in manually?
 
Upvote 0
Yes. I wrote it manually prior to working on getting the code to auto insert.
 
Upvote 0
You sure about that? ;)
You've got two ( but only one )
 
Upvote 0
Hmmm...If the training date is 7/7/19 it will blank the cell, but it will retain COMPLETED, but now that you mention it the cell does not retain a date of say 5/5/2020. What am I missing?
 
Upvote 0
That code looks fine to me, are you sure the formula(s) aren't getting inserted?

The only possible problem I can see is with the formula itself, specifically the expression in your IF function.

Something like G3>12/31/2019 will not do a date comparison, in fact it will compare G3 to the value 0.000191727, i.e. the result of 12 divided by 31 divided by 2019.

Try replacing the expression with G3>DATE(2019,12,31).

Worksheets("New Year").range("J3:J" & lastRow).Formula = "=If(G3>DATE(2019,12,31),G3,If(G3=""COMPLETED"",""COMPLETED"","" "")"
 
Upvote 0
Thank you for the update to the formula....The column is highlighted down to the last row but the cells are empty. It is weird
 
Upvote 0
Try
"=If(G3>DATE(2019,12,31),G3,If(G3=""COMPLETED"",""COMPLETED"","" ""))"
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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