PC Review


Reply
Thread Tools Rate Thread

Applying a formula to a cell

 
 
=?Utf-8?B?VG9tIFJvYmVydHM=?=
Guest
Posts: n/a
 
      14th Aug 2007
I would like to set up a button in a spreadsheet that adds 2 years to the
value of of the currently selected cell containing a date. the forumla would
look something like this: =DATE(YEAR(A1)+2,MONTH(A2),DAY(A3)) but is there a
way I can have this formula applied to a cell when I press a button? I would
like the cell to contain the result, rather than the formula.
Thanks guys.
 
Reply With Quote
 
 
 
 
Brian Withun
Guest
Posts: n/a
 
      14th Aug 2007
On Aug 14, 12:02 pm, Tom Roberts
<TomRobe...@discussions.microsoft.com> wrote:
> I would like to set up a button in a spreadsheet that adds 2 years to the
> value of of the currently selected cell containing a date. the forumla would
> look something like this: =DATE(YEAR(A1)+2,MONTH(A2),DAY(A3)) but is there a
> way I can have this formula applied to a cell when I press a button? I would
> like the cell to contain the result, rather than the formula.
> Thanks guys.


try this event for your button:

Private Sub AddTwoYears_Click()

Dim CurrentValue As Date
On Error GoTo CannotConvertToDate
Let CurrentValue = Selection.Value
On Error GoTo 0
Selection.Value = DateSerial(Year(CurrentValue) + 2,
Month(CurrentValue), Day(CurrentValue))
Exit Sub

CannotConvertToDate:
MsgBox "Selection is not a date"

End Sub

Brian Herbert Withun

 
Reply With Quote
 
=?Utf-8?B?VG9tIFJvYmVydHM=?=
Guest
Posts: n/a
 
      15th Aug 2007
Thanks Brian, that was exactly what I was looking for. Makes me realize I
need to learn VB!

"Brian Withun" wrote:

> On Aug 14, 12:02 pm, Tom Roberts
> <TomRobe...@discussions.microsoft.com> wrote:
> > I would like to set up a button in a spreadsheet that adds 2 years to the
> > value of of the currently selected cell containing a date. the forumla would
> > look something like this: =DATE(YEAR(A1)+2,MONTH(A2),DAY(A3)) but is there a
> > way I can have this formula applied to a cell when I press a button? I would
> > like the cell to contain the result, rather than the formula.
> > Thanks guys.

>
> try this event for your button:
>
> Private Sub AddTwoYears_Click()
>
> Dim CurrentValue As Date
> On Error GoTo CannotConvertToDate
> Let CurrentValue = Selection.Value
> On Error GoTo 0
> Selection.Value = DateSerial(Year(CurrentValue) + 2,
> Month(CurrentValue), Day(CurrentValue))
> Exit Sub
>
> CannotConvertToDate:
> MsgBox "Selection is not a date"
>
> End Sub
>
> Brian Herbert Withun
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Applying Formula to cell Graham Microsoft Excel Programming 2 25th Mar 2010 11:55 AM
Applying a cell format within a Formula =?Utf-8?B?QlJNZXRlcg==?= Microsoft Excel Misc 2 21st Aug 2007 03:46 PM
Applying Formula Based on Cell Contents =?Utf-8?B?dmlsamE=?= Microsoft Excel Programming 5 8th Nov 2006 05:30 PM
applying formula =?Utf-8?B?UGF0IE4u?= Microsoft Excel Misc 1 25th Apr 2006 08:47 PM
Applying conditional formatting to cell based on another cell's in =?Utf-8?B?a2Rlc2VtcGxl?= Microsoft Excel Misc 1 22nd Mar 2006 06:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:17 PM.