Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Worksheet change VBA

Ok I'm in need of some help:
On my worksheet i have a cell with a validation drop box. The following code
filters the page when the user selects a value from the drop box. Problem is
I want it also to clear cell contents in cell c4. I know how to write it to
clear the contents but once you type something in c4 then the filter runs
again thus clearing the contents again. I understand this means the macro
runs anytime something is changed in the workshet. How do I write it to work
only when the drop down box is used. That way the user can change things on
the worksheet without it running the macro. The following is my code thus far:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 3 Then
'calculate criteria cell in case calculation mode is manual
Worksheets("ProduceData").Range("Q2").Calculate
Worksheets("ProduceData").Range("Database") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("ProduceData").Range("q1:q2" ), _
CopyToRange:=Range("a7:f7"), Unique:=False
End If

End Sub
--
Though daily learning, I LOVE EXCEL!
Jennifer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Worksheet change VBA

Private Sub Worksheet_Change(ByVal Target As Range)
On Erroro Goto ws_exit
Application.EnableEvents = False
If Target.Row = 3 And Target.Column = 3 Then
'calculate criteria cell in case calculation mode is manual
Worksheets("ProduceData").Range("Q2").Calculate
Worksheets("ProduceData").Range("Database") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("ProduceData").Range("q1:q2" ), _
CopyToRange:=Range("a7:f7"), Unique:=False
Me.Range("C3").ClearContents
End If
ws_exit:
Application.EnableEvents = True
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jennifer" wrote in message
...
Ok I'm in need of some help:
On my worksheet i have a cell with a validation drop box. The following

code
filters the page when the user selects a value from the drop box. Problem

is
I want it also to clear cell contents in cell c4. I know how to write it

to
clear the contents but once you type something in c4 then the filter runs
again thus clearing the contents again. I understand this means the macro
runs anytime something is changed in the workshet. How do I write it to

work
only when the drop down box is used. That way the user can change things

on
the worksheet without it running the macro. The following is my code thus

far:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 3 Then
'calculate criteria cell in case calculation mode is manual
Worksheets("ProduceData").Range("Q2").Calculate
Worksheets("ProduceData").Range("Database") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("ProduceData").Range("q1:q2" ), _
CopyToRange:=Range("a7:f7"), Unique:=False
End If

End Sub
--
Though daily learning, I LOVE EXCEL!
Jennifer



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Worksheet change VBA

It worked. Thanks a bunch!
Why when I protect the sheet does the filter not work? I added
Activesheet.unprotect to the vba and it still doesn't work.

Thank you!

"Jennifer" wrote:

Ok I'm in need of some help:
On my worksheet i have a cell with a validation drop box. The following code
filters the page when the user selects a value from the drop box. Problem is
I want it also to clear cell contents in cell c4. I know how to write it to
clear the contents but once you type something in c4 then the filter runs
again thus clearing the contents again. I understand this means the macro
runs anytime something is changed in the workshet. How do I write it to work
only when the drop down box is used. That way the user can change things on
the worksheet without it running the macro. The following is my code thus far:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 3 Then
'calculate criteria cell in case calculation mode is manual
Worksheets("ProduceData").Range("Q2").Calculate
Worksheets("ProduceData").Range("Database") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("ProduceData").Range("q1:q2" ), _
CopyToRange:=Range("a7:f7"), Unique:=False
End If

End Sub
--
Though daily learning, I LOVE EXCEL!
Jennifer

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Worksheet change VBA

Do you unprotect the sheet before you alter the autofilter?

You can also do

Activesheet.Protect UserInferfaceOnly:=True
ActiveSheet.enableAutofilter

this works with an existing filter but won't create a new one.

--
regards,
Tom Ogilvy

"Jennifer" wrote in message
...
It worked. Thanks a bunch!
Why when I protect the sheet does the filter not work? I added
Activesheet.unprotect to the vba and it still doesn't work.

Thank you!

"Jennifer" wrote:

Ok I'm in need of some help:
On my worksheet i have a cell with a validation drop box. The following

code
filters the page when the user selects a value from the drop box.

Problem is
I want it also to clear cell contents in cell c4. I know how to write it

to
clear the contents but once you type something in c4 then the filter

runs
again thus clearing the contents again. I understand this means the

macro
runs anytime something is changed in the workshet. How do I write it to

work
only when the drop down box is used. That way the user can change things

on
the worksheet without it running the macro. The following is my code

thus far:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 3 Then
'calculate criteria cell in case calculation mode is manual
Worksheets("ProduceData").Range("Q2").Calculate
Worksheets("ProduceData").Range("Database") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("ProduceData").Range("q1:q2" ), _
CopyToRange:=Range("a7:f7"), Unique:=False
End If

End Sub
--
Though daily learning, I LOVE EXCEL!
Jennifer



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 change the pivot chart automaticaly as values in the worksheet change Vinay Vasu Excel Worksheet Functions 0 May 3rd 10 04:25 PM
change formula in a shared worksheet without losing change history DCE Excel Worksheet Functions 5 July 25th 08 01:37 PM
Help Please, Worksheet Change ilvmgicker Excel Worksheet Functions 1 June 14th 06 09:41 AM
Worksheet Change SeanEvans[_4_] Excel Programming 1 November 24th 04 03:29 PM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM


All times are GMT +1. The time now is 06:46 AM.

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"