Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Macro to add 1 or more days to a date

Hi everyone

using Xl2002:
I'm trying to create a macro to select cell B2 which
contains a dd-mm-yyy date format and add or delete a
number of days depending on a number enter into a second
cell E2( I am assumming that by entering a minus -2 in
this cell the macro would take 2 days off).
i.e. 1-May-2004 would become 29-April-2004.
The macro wiil be attached to a form button.

TIA

Bob C.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Macro to add 1 or more days to a date

Robert,

this code example would go into the sheet's code module,
entering a negative value in b1 would(ofcourse) lower a1's date while a
positive number would increase it.

note: \ 1 is equivalent to cint([a1]) (makes it an integer)
note: [a1] is short notation for cell A1 on the activesheet


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

'Doubleclicking A1 will add B1 to it's value
If Target.Address < "$A$1" Then
Exit Sub
ElseIf [b1].Value = 0 Then
Exit Sub
Else
If IsEmpty([a1]) Then [a1] = Date
'note: all rounded to integers
[a1] = [a1] \ 1 + [b1] \ 1
End If

End Sub

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Robert Christie" wrote:

Hi everyone

using Xl2002:
I'm trying to create a macro to select cell B2 which
contains a dd-mm-yyy date format and add or delete a
number of days depending on a number enter into a second
cell E2( I am assumming that by entering a minus -2 in
this cell the macro would take 2 days off).
i.e. 1-May-2004 would become 29-April-2004.
The macro wiil be attached to a form button.

TIA

Bob C.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Macro to add 1 or more days to a date

Hi keepitcool

Thank you for your quick reply and the code is working A
OK.

I added a Range("??").Select line of code before the End
Sub last line to move curser to a 'neutral corner' as a
safety measure and to be able to doubleclick the Cell A1
again. As you know Doubleclicking a cell allows you to
edit in the cell.

Thank You

Regards Bob C.


-----Original Message-----
Robert,

this code example would go into the sheet's code module,
entering a negative value in b1 would(ofcourse) lower

a1's date while a
positive number would increase it.

note: \ 1 is equivalent to cint([a1]) (makes it an

integer)
note: [a1] is short notation for cell A1 on the

activesheet


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As

Range, Cancel As
Boolean)

'Doubleclicking A1 will add B1 to it's value
If Target.Address < "$A$1" Then
Exit Sub
ElseIf [b1].Value = 0 Then
Exit Sub
Else
If IsEmpty([a1]) Then [a1] = Date
'note: all rounded to integers
[a1] = [a1] \ 1 + [b1] \ 1
End If

End Sub

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Robert Christie"

wrote:

Hi everyone

using Xl2002:
I'm trying to create a macro to select cell B2 which
contains a dd-mm-yyy date format and add or delete a
number of days depending on a number enter into a

second
cell E2( I am assumming that by entering a minus -2 in
this cell the macro would take 2 days off).
i.e. 1-May-2004 would become 29-April-2004.
The macro wiil be attached to a form button.

TIA

Bob C.


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Macro to add 1 or more days to a date

You can set the Cancel property to True instead of "moving the cursor":

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
With Target
If .Address(False, False) = "B2" Then
Cancel = True
If IsNumeric(Range("E2").Value) Then _
.Value = .Value + Int(Range("E2").Value)
End If
End With
End Sub



In article ,
"Robert Christie" wrote:

I added a Range("??").Select line of code before the End
Sub last line to move curser to a 'neutral corner' as a
safety measure and to be able to doubleclick the Cell A1
again. As you know Doubleclicking a cell allows you to
edit in the cell.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Macro to add 1 or more days to a date

Hi JE
Thank you for your post, it works well.
But why oh why are there so many ways to achieve the same
thing in Excel.
It certainly makes mastering Excel very hard.

Thank you

Regards Bob C.


-----Original Message-----
You can set the Cancel property to True instead

of "moving the cursor":

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
With Target
If .Address(False, False) = "B2" Then
Cancel = True
If IsNumeric(Range("E2").Value) Then _
.Value = .Value + Int(Range

("E2").Value)
End If
End With
End Sub



In article ,
"Robert Christie"

wrote:

I added a Range("??").Select line of code before the

End
Sub last line to move curser to a 'neutral corner' as

a
safety measure and to be able to doubleclick the Cell

A1
again. As you know Doubleclicking a cell allows you to
edit in the cell.

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Macro to add 1 or more days to a date

Hi Again JE

Is it possible to have more than 2

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)

in the same sheet.
I tried adding '_two' after DoubleClick and changing cell
references but it did not work.

TIA

Regards Bob C.


-----Original Message-----
You can set the Cancel property to True instead

of "moving the cursor":

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
With Target
If .Address(False, False) = "B2" Then
Cancel = True
If IsNumeric(Range("E2").Value) Then _
.Value = .Value + Int(Range

("E2").Value)
End If
End With
End Sub



In article ,
"Robert Christie"

wrote:

I added a Range("??").Select line of code before the

End
Sub last line to move curser to a 'neutral corner' as

a
safety measure and to be able to doubleclick the Cell

A1
again. As you know Doubleclicking a cell allows you to
edit in the cell.

.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro to add 1 or more days to a date

Robert,

No, you cannot have more than one event procedure for an event.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Robert Christie" wrote in
message ...
Hi Again JE

Is it possible to have more than 2

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)

in the same sheet.
I tried adding '_two' after DoubleClick and changing cell
references but it did not work.

TIA

Regards Bob C.


-----Original Message-----
You can set the Cancel property to True instead

of "moving the cursor":

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
With Target
If .Address(False, False) = "B2" Then
Cancel = True
If IsNumeric(Range("E2").Value) Then _
.Value = .Value + Int(Range

("E2").Value)
End If
End With
End Sub



In article ,
"Robert Christie"

wrote:

I added a Range("??").Select line of code before the

End
Sub last line to move curser to a 'neutral corner' as

a
safety measure and to be able to doubleclick the Cell

A1
again. As you know Doubleclicking a cell allows you to
edit in the cell.

.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to pull <=14 Days, <=30 Days, 30 Days from a date column Ken Excel Discussion (Misc queries) 3 October 23rd 09 12:53 AM
Conditional Formatting Dates calculating 10 days and 30 days from a certain date Sioux[_2_] Excel Worksheet Functions 2 October 11th 07 02:04 PM
Report Date - Date Recv = Days Late, but how to rid completed date MS Questionnairess Excel Worksheet Functions 1 January 24th 07 11:05 PM
Excel Formula to calulate number of days passed from date to date K. Mack Excel Discussion (Misc queries) 8 January 4th 07 11:27 PM
Calculating days between current date and a date in future NETWORKDAYS() function Faheem Khan Excel Worksheet Functions 2 February 10th 05 07:18 PM


All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"