Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Complex date VBA - insert a certain weekday



Hi All

I use this code to place the current date (dd mmm yyyy) in a range of
cells when content is added to cells adjacent to them :


Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)
On Error GoTo enditall
Application.EnableEvents = False
If Intersect(Range(Target(1).Address), _
Range("B:B, D:D, F:F, H:H, J:J, L:L")) _
Is Nothing Then GoTo enditall
With Target
If .Value < "" Then
With .Offset(0, -1)
.Value = Date + 1
'.Columns.AutoFit
End With
Else: .Offset(0, -1).Value = ""
End If
End With
enditall:
Application.EnableEvents = True
End Sub


Is it possible to have this place the next Tuesday's date (dd mmm yyyy)
in the cells , instead of the current date?


Can someone assist with an adaptation of the code?


Grateful for any advice.




  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default Complex date VBA - insert a certain weekday

Hi Colin,

Am Tue, 23 Jul 2013 17:29:34 +0100 schrieb Colin Hayes:

With Target
If .Value < "" Then
With .Offset(0, -1)
.Value = Date + 1
'.Columns.AutoFit
End With
Else: .Offset(0, -1).Value = ""
End If
End With
Is it possible to have this place the next Tuesday's date (dd mmm yyyy)
in the cells , instead of the current date?


try:
If Target.Value < "" Then
With WorksheetFunction
Target.Offset(0, -1) = Date + _
.Choose(.Weekday(Date), 2, 1, 7, 6, 5, 4, 3)
End With
'.Columns.AutoFit
Else: Target.Offset(0, -1).Value = ""
End If


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,045
Default Complex date VBA - insert a certain weekday

On Tue, 23 Jul 2013 17:29:34 +0100, Colin Hayes wrote:

.Value = Date + 1


I note this is putting in tomorrow's date, not today's date

but for next Tuesday, change to:

..Value = Date + 8 - Weekday(Date + 5)
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Complex date VBA - insert a certain weekday

In article , Ron Rosenfeld
writes
On Tue, 23 Jul 2013 17:29:34 +0100, Colin Hayes
wrote:

.Value = Date + 1


I note this is putting in tomorrow's date, not today's date

but for next Tuesday, change to:

.Value = Date + 8 - Weekday(Date + 5)




OK thanks for these solutions. Both work perfectly first time.

^_^
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Complex date VBA - insert a certain weekday


On Tue, 23 Jul 2013 17:29:34 +0100, Colin Hayes
wrote:

.Value = Date + 1


I note this is putting in tomorrow's date, not today's date

but for next Tuesday, change to:

.Value = Date + 8 - Weekday(Date + 5)




OK thanks for these solutions. Both work perfectly first time.

^_^


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,045
Default Complex date VBA - insert a certain weekday

On Wed, 24 Jul 2013 02:04:47 +0100, Colin Hayes wrote:


On Tue, 23 Jul 2013 17:29:34 +0100, Colin Hayes
wrote:

.Value = Date + 1


I note this is putting in tomorrow's date, not today's date

but for next Tuesday, change to:

.Value = Date + 8 - Weekday(Date + 5)




OK thanks for these solutions. Both work perfectly first time.

^_^


Glad to help. Thanks for the feedback.
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Complex date VBA - insert a certain weekday

In article , Ron Rosenfeld
writes
On Wed, 24 Jul 2013 02:04:47 +0100, Colin Hayes
wrote:


On Tue, 23 Jul 2013 17:29:34 +0100, Colin Hayes


wrote:

.Value = Date + 1

I note this is putting in tomorrow's date, not today's date

but for next Tuesday, change to:

.Value = Date + 8 - Weekday(Date + 5)




Hi

Just a small follow-up to this. I used the code

Value = Date + 8 - Weekday(Date + 5)

to give an output of

30 Jul 2013

When I added some text to the code :

..Value = "Tuesday " & Date + 8 - Weekday(Date + 5)

the output becomes

Tuesday 30/07/2013.

It seems to have lost the previous formatting. Is it possible to have it
read
Tuesday 30 Jul 2103 , do you know?


Thanks again

Best Wishes



  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,045
Default Complex date VBA - insert a certain weekday

On Wed, 24 Jul 2013 19:00:52 +0100, Colin Hayes wrote:

In article , Ron Rosenfeld
writes
On Wed, 24 Jul 2013 02:04:47 +0100, Colin Hayes
wrote:


On Tue, 23 Jul 2013 17:29:34 +0100, Colin Hayes


wrote:

.Value = Date + 1

I note this is putting in tomorrow's date, not today's date

but for next Tuesday, change to:

.Value = Date + 8 - Weekday(Date + 5)



Hi

Just a small follow-up to this. I used the code

Value = Date + 8 - Weekday(Date + 5)

to give an output of

30 Jul 2013

When I added some text to the code :

.Value = "Tuesday " & Date + 8 - Weekday(Date + 5)

the output becomes

Tuesday 30/07/2013.

It seems to have lost the previous formatting. Is it possible to have it
read
Tuesday 30 Jul 2103 , do you know?


Thanks again

Best Wishes



By adding the text string, you have converted the entire value into text, so the date being displayed is probably your windows regional short date (that's just a guess).

If you want to ensure the date is displayed in the cell how you want, you should format the cell appropriately.

e.g. ...
.value = Date + 8 - weekday(Date+5)
.numberformat = "dddd dd mmm yyyy"
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Complex date VBA - insert a certain weekday

In article , Ron Rosenfeld
writes
By adding the text string, you have converted the entire value into text, so the date
being displayed
is probably your windows regional short date (that's just a guess).

If you want to ensure the date is displayed in the cell how you want, you should
format the cell
appropriately.

e.g. ...
.value = Date + 8 - weekday(Date+5)
.numberformat = "dddd dd mmm yyyy"


Hi Ron

OK thanks for that. That's fixed it in the desired format.

The cell now curiously refuses to wrap the text for some reason , but
I'll continue to fiddle with it so it's not too wide for the other cells
in the sheet.



Best Wishes

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
How to compute date of next weekday? [email protected] Excel Discussion (Misc queries) 4 July 31st 08 02:05 AM
convert weekday date to the next sunday date Oldersox Excel Worksheet Functions 2 January 8th 07 11:26 AM
WEEKDAY() function: display TEXT not numeric weekday tom Excel Discussion (Misc queries) 3 November 21st 06 04:32 PM
MATCHING DATE TO A WEEKDAY Stuart Carnachan Excel Worksheet Functions 3 October 31st 06 05:19 PM
Getting weekday for a date schoujar[_7_] Excel Programming 6 September 2nd 05 11:01 AM


All times are GMT +1. The time now is 08:52 PM.

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

About Us

"It's about Microsoft Excel"