Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Nested if's in vba

This code (when split into two seperate codes works fine):
The first automatically inserts date and time in the adjacent cells, while
the second changes cell colour depending on which (week)day it is:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("C7:c5000")) Is Nothing Then
With Target
If .Value < "" Then
.Offset(0, -1).Value = Format(Now, "hh:mm:ss")
.Offset(0, -2).Value = Format(Date, "dd/mmm")
End If
End With
End If

If Not Intersect(Target, Me.Range("A7:A5000")) Is Nothing Then
With Target
Select Case Application.Weekday(.Value, 2)
Case 1: .Interior.ColorIndex = 19
Case 2: .Interior.ColorIndex = 34
Case 3: .Interior.ColorIndex = 38
Case 4: .Interior.ColorIndex = 40
Case 5: .Interior.ColorIndex = 44
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

I have tried to add both codes but when the date is automatically inserted
by code rather than input by the user, no colour change is initiated.
Is there a way around this?
Thanks
--
tia

Jock
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Nested if's in vba

Repeat (with modification) the coloring code in the first IF...THEN
block, or put the coloring code in a seperate Sub and have both
IF...THEN blocks call it.

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
dq dq is offline
external usenet poster
 
Posts: 46
Default Nested if's in vba

The problem is that Excel doesn't react to the automatic insertion
because of the line
Application.EnableEvents = False
Put the line
Application.EnableEvents = True
immediatly before the line
..Offset(0, -2).Value = Format(Date, "dd/mmm")
this will trigger your function again, but now with the target being
in column A.

DQ

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Nested if's in vba

Brilliant! Thank you
--
tia

Jock


"dq" wrote:

The problem is that Excel doesn't react to the automatic insertion
because of the line
Application.EnableEvents = False
Put the line
Application.EnableEvents = True
immediatly before the line
..Offset(0, -2).Value = Format(Date, "dd/mmm")
this will trigger your function again, but now with the target being
in column A.

DQ


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
Nested If's Beverly Excel Worksheet Functions 2 October 10th 08 08:54 PM
A problem with nested IF's The Narcissist Excel Worksheet Functions 0 January 23rd 08 12:10 AM
Nested If's Cletus Stripling Excel Worksheet Functions 4 September 30th 05 01:14 PM
How many nested IF's??? malik641 Excel Discussion (Misc queries) 1 June 16th 05 09:35 PM
NESTED IF's too many saturnin02 Excel Programming 11 July 24th 03 07:26 PM


All times are GMT +1. The time now is 02:56 PM.

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"