Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Format using VBA not activating when needed

In the following procedure, how do I have the formatting occur as soon as
the operator exits the cell (either by the keyboard or mouse)? At the moment
this procedure requires the operator to exit and then activate that cell
again.

Rob

Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub

If Me.Cells(Target.Row, "K") = "" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If

If Me.Cells(Target.Row, "K") = "AH" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 120
Default Format using VBA not activating when needed

Hi Rob

It's not working as the target is the destination cell/range, that's
why you have to click out then go back to modify row K. I'd work this
by storing the activate range on startup using worksheet_activate in
say variable1 and on a selection change put this range in variable2,
then check to see if variable1 matches criteria, if yes run code, if
not set variable1 = variable2.
Alternatively have a look at the change event.

hth

keith

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Format using VBA not activating when needed

You've got it working on the active cell and not the target cell, try this:-

Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub

If Me.Cells(Target.Row, "K") = "" Then
With Target.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If

If Me.Cells(Target.Row, "K") = "AH" Then
With Target.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If

Mike

"RobN" wrote:

In the following procedure, how do I have the formatting occur as soon as
the operator exits the cell (either by the keyboard or mouse)? At the moment
this procedure requires the operator to exit and then activate that cell
again.

Rob

Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub

If Me.Cells(Target.Row, "K") = "" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If

If Me.Cells(Target.Row, "K") = "AH" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Format using VBA not activating when needed

Mike,

I tried that but it doesn't make any difference. I still need to enter a
value in the cell, exit it and reactivate that cell for the formatting to
work.

Rob

"Mike H" wrote in message
...
You've got it working on the active cell and not the target cell, try
this:-

Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub

If Me.Cells(Target.Row, "K") = "" Then
With Target.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If

If Me.Cells(Target.Row, "K") = "AH" Then
With Target.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If

Mike

"RobN" wrote:

In the following procedure, how do I have the formatting occur as soon as
the operator exits the cell (either by the keyboard or mouse)? At the
moment
this procedure requires the operator to exit and then activate that cell
again.

Rob

Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub

If Me.Cells(Target.Row, "K") = "" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If

If Me.Cells(Target.Row, "K") = "AH" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If

End Sub





  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Format using VBA not activating when needed

Keith,

Thankyou for that explanation. I went for your alternative suggestion, by
changing from Worksheet_SelectionChange to Worksheet_Change, and it works
great.

Rob

"Keith74" wrote in message
...
Hi Rob

It's not working as the target is the destination cell/range, that's
why you have to click out then go back to modify row K. I'd work this
by storing the activate range on startup using worksheet_activate in
say variable1 and on a selection change put this range in variable2,
then check to see if variable1 matches criteria, if yes run code, if
not set variable1 = variable2.
Alternatively have a look at the change event.

hth

keith



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
Time format help needed Dan W. Excel Worksheet Functions 19 March 6th 08 09:08 AM
Activating wrap text format causes my text to disappear, why? Oli Excel Discussion (Misc queries) 2 March 5th 07 10:46 PM
IF / Else Format help needed Paul B. Excel Worksheet Functions 5 January 5th 06 06:37 PM
Help needed to format x-axis of graph mj123 Excel Discussion (Misc queries) 0 September 13th 05 02:26 AM
Help needed with date format [email protected] Excel Discussion (Misc queries) 1 August 29th 05 09:11 AM


All times are GMT +1. The time now is 08:27 AM.

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"