Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default On Got Focus, Clear Cells

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default On Got Focus, Clear Cells

Expanding the Validation Drop Down is not an event that is tracked by XL. The
closest things are the select and change events. Select fires when the cell
is selected. Change fires when the cell changes. Would change work for you.
Once and item is selected from the validation list then the cells are
cleared??? That is not too difficult to do...
--
HTH...

Jim Thomlinson


"Suzanne" wrote:

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default On Got Focus, Clear Cells

Change will do it too... I was trying to manipulate other solutions with
change (with no success). I appreciate your help.

Suz

"Jim Thomlinson" wrote:

Expanding the Validation Drop Down is not an event that is tracked by XL. The
closest things are the select and change events. Select fires when the cell
is selected. Change fires when the cell changes. Would change work for you.
Once and item is selected from the validation list then the cells are
cleared??? That is not too difficult to do...
--
HTH...

Jim Thomlinson


"Suzanne" wrote:

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default On Got Focus, Clear Cells

This should be pretty close...

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
Select Case .Column
Case 1 'column a
Application.EnableEvents = False
Cells(Target.Row, "B").ClearContents
Cells(Target.Row, "D").ClearContents
Cells(Target.Row, "E").ClearContents
Application.EnableEvents = True
Case 5 'column e
Application.EnableEvents = False
Cells(Target.Row, "B").ClearContents
Cells(Target.Row, "D").ClearContents
Cells(Target.Row, "A").ClearContents
Application.EnableEvents = True
End Select
End With
End Sub
--
HTH...

Jim Thomlinson


"Suzanne" wrote:

Change will do it too... I was trying to manipulate other solutions with
change (with no success). I appreciate your help.

Suz

"Jim Thomlinson" wrote:

Expanding the Validation Drop Down is not an event that is tracked by XL. The
closest things are the select and change events. Select fires when the cell
is selected. Change fires when the cell changes. Would change work for you.
Once and item is selected from the validation list then the cells are
cleared??? That is not too difficult to do...
--
HTH...

Jim Thomlinson


"Suzanne" wrote:

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default On Got Focus, Clear Cells

Sorry this is a little cleaner. The original code will work but this is a tad
better...

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
Select Case .Column
Case 1 'column a
Application.EnableEvents = False
Cells(.Row, "B").ClearContents
Cells(.Row, "D").ClearContents
Cells(.Row, "E").ClearContents
Application.EnableEvents = True
Case 5 'column e
Application.EnableEvents = False
Cells(.Row, "B").ClearContents
Cells(.Row, "D").ClearContents
Cells(.Row, "A").ClearContents
Application.EnableEvents = True
End Select
End With
End Sub

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

This should be pretty close...

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
Select Case .Column
Case 1 'column a
Application.EnableEvents = False
Cells(Target.Row, "B").ClearContents
Cells(Target.Row, "D").ClearContents
Cells(Target.Row, "E").ClearContents
Application.EnableEvents = True
Case 5 'column e
Application.EnableEvents = False
Cells(Target.Row, "B").ClearContents
Cells(Target.Row, "D").ClearContents
Cells(Target.Row, "A").ClearContents
Application.EnableEvents = True
End Select
End With
End Sub
--
HTH...

Jim Thomlinson


"Suzanne" wrote:

Change will do it too... I was trying to manipulate other solutions with
change (with no success). I appreciate your help.

Suz

"Jim Thomlinson" wrote:

Expanding the Validation Drop Down is not an event that is tracked by XL. The
closest things are the select and change events. Select fires when the cell
is selected. Change fires when the cell changes. Would change work for you.
Once and item is selected from the validation list then the cells are
cleared??? That is not too difficult to do...
--
HTH...

Jim Thomlinson


"Suzanne" wrote:

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default On Got Focus, Clear Cells

This works in the selection event, not quite as you ask but see if it meets
your needs.

It goes in the Worksheet module, right-click tab, view code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Dim col As Long

col = Target(1).Column
If col = 1 Or col = 5 Then
On Error Resume Next
nt = ActiveCell.Validation.Type
On Error GoTo 0
If nt = 3 Then
If col = 1 Then
Set rng = Range("B1,D1:E1")
Else
Set rng = Range("A1:B1,D1")
End If
rng.Offset(Target.Row - 1).ClearContents
End If
End If

End Sub

Regards,
Peter T

"Suzanne" wrote in message
...
I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation

drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default On Got Focus, Clear Cells

Thanks VERY much! Jim, your formula did the trick.

Peter: I tried out your formula (I think I got it in right); but came up
with a var not defined error.

"Suzanne" wrote:

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default On Got Focus, Clear Cells

Hi Suzanne,

I take it you have Option Explicit at the top of the module, which is good,
and I forgot to declare 'nt' like this -
Dim nt as Long

I wasn't sure if you want to clear cells if any cell in column A or E is
selected, or only when selecting cells in those columns with a valadation
list, which is what is looked for in the routine I posted. If that's what
you want, for clarity could change -

If nt = 3 Then

to
If nt = xlValidateList Then

Regards,
Peter T


"Suzanne" wrote in message
...
Thanks VERY much! Jim, your formula did the trick.

Peter: I tried out your formula (I think I got it in right); but came up
with a var not defined error.

"Suzanne" wrote:

I can't quite figure out the right code for this:

On selection (GotFocus) of a validation drop-down in Column A, clear

cells
in Columns B, D, & E; OR on selection (GotFocus) of the validation

drop-down
in Column E, clear cells in Columns A, B, & D

Only the cells on the row with focus should be cleared

Thanks -- Suzanne



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
Create a Clear button to clear unprotected cells Jcraig713 Excel Programming 2 November 26th 07 03:55 PM
Clear cells One-Leg Excel Programming 3 June 3rd 06 12:20 AM
clear contents cells of unprotected cells Ed Excel Programming 6 January 12th 06 06:09 PM
Clear cells with #N/A mthomas[_6_] Excel Programming 4 August 12th 05 04:24 PM
Clear cells range if certain cells are all empty gschimek - ExcelForums.com Excel Programming 6 May 13th 05 10:38 PM


All times are GMT +1. The time now is 01:14 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"