If then else

Microsoft Ms slb word lic/sa
June 9, 2010 at 02:19:12
Specs: Windows Vista
I am trying to create an if then else statement as follows

if "date" add 14 "new date"

is this possible?

See More: If then else

Report •

June 9, 2010 at 04:41:19
is this possible?
Yes, but it would be so much easier if we had more information.

The structure of an IF statement is:

=IF(logical_test, value_if_true, value_if_false)

We know part of your "value_if_true" is that you need to add 14 (I'm guessing it's 14 days not 14 months or 14 years).

Don't know much else about what your trying to do, or what your sheet looks like.



Report •

June 9, 2010 at 08:23:42

You could use a custom 'user defined function'

Open the VBA window by right-clicking the worksheet name tab and 'View Code'
Then right-click the highlighted worksheet name in the left-side pane.
Select 'Insert' then 'Module' (not Class module)
Paste this into the large VBA window on the right-side:

Public Function Plus14(datecell As Range)
If IsDate(datecell.Value) Then
    'is a date so add 14
    Plus14 = datecell.Value + 14
    'not a date, so return blank
    Plus14 = ""
End If
End Function

Click File - Save from the VBA menu bar

This is pretty basic - no error checks etc.

Click Alt+f11 to return to the main Excel window.

If you have dates / other values in column A, starting at A1, put this in cell B1:
Drag the formula down from B1 as many rows as you have data in column A

This function will return a value which is the date + 14 days if the referenced cell contains a valid Excel date. If the cell does not contain a date it returns "".

You will need to format the cells with the date format required.
I don't think that you can format the cell with the user defined function automatically from within the function - but perhaps someone else will say if it is possible.


Report •

Related Solutions

Ask Question