Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Create a Clear button to clear unprotected cells | Excel Programming | |||
Clear cells | Excel Programming | |||
clear contents cells of unprotected cells | Excel Programming | |||
Clear cells with #N/A | Excel Programming | |||
Clear cells range if certain cells are all empty | Excel Programming |