PDA

View Full Version : how to use an input box to create a formula



bananatang
07-29-2009, 08:08 AM
Hi,

Need some help on this one.

I have the following formula "=DATEDIF(F2,"31/08/09","Y")"

I would like to have a macro that will apply this formula to cell T2, however i need an input box that will allow me to change the date ie 31/08/09 within the formula.

Thanks

BT

mdmackillop
07-29-2009, 09:42 AM
Range("T2").Formula = "=DATEDIF(F2," & """" & InputBox("Enter date") & """" & ",""Y"")"

bananatang
07-30-2009, 03:04 AM
Hi,

mdmackillop thanks for the code, however i would appreciate abit of further assistance. I thought i could easily modify the code to allow me to apply a filter box to another formula, however this formula is based on numbers and not text.

The formula that i want to apply to column W2 was =IF(T2>=23,1,0) in which i wanted the input box to request what number did i wish to insert

The difficulty i am having is that the end portion of the code, i seem to get a text value for the 1, 0.

My code is as follows

Range("W2").Formula = "=IF(T2>=" & "" & InputBox("Enter No. of Sessions") & "" & ",""1"", ""0"")"

I have tried moving the additional "" but that caused an error.

Thanks

BT

Bob Phillips
07-30-2009, 03:10 AM
Range("W2").Formula = "=--(T2>=" & "" & InputBox("Enter No. of Sessions") & ")"