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

Hello all,

I'm trying to use the workshee_change event to grab the value of the current
filter criteria1 and then paste that value into a particular cell. However,
it's not working. Anyone have ideas? Here's the code;

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Address = "$H$991" Then
'Application.EnableEvents = False
If Target.Value = 10 Then
With ActiveWorkbook
If .AutoFilterMode Then
With .AutoFilter.Filters(1)
If .On Then c1 = .Criteria1
Range("F992").Value = c1
End With
End If
End With
End If
' Application.EnableEvents = True
End If
End Sub

Cheers,

Job


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Worksheet_Change

Filters belong to the worksheet--not the workbook.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim c1 As String

If Target.Address = "$H$991" Then
Application.EnableEvents = False
If Target.Value = 10 Then
With Me
If .AutoFilterMode Then
With Me.AutoFilter.Filters(1)
If .On Then
c1 = .Criteria1
End If
Range("F992").Value = c1
End With
End If
End With
End If
Application.EnableEvents = True
End If
End Sub

I turned on the enableevents stuff. If you're changing another cell, you
probably don't want the code to fire again.

The Me. refers to the thing that we'er in. Since we'er in a worksheet module,
it refers to the worksheet owning the code.

(I also changed your if/then into a multiple line if/then. I just find that
easier to read when it's in that portion of code--but that's just my
preference.)

Job wrote:

Hello all,

I'm trying to use the workshee_change event to grab the value of the current
filter criteria1 and then paste that value into a particular cell. However,
it's not working. Anyone have ideas? Here's the code;

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Address = "$H$991" Then
'Application.EnableEvents = False
If Target.Value = 10 Then
With ActiveWorkbook
If .AutoFilterMode Then
With .AutoFilter.Filters(1)
If .On Then c1 = .Criteria1
Range("F992").Value = c1
End With
End If
End With
End If
' Application.EnableEvents = True
End If
End Sub

Cheers,

Job


--

Dave Peterson

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
Worksheet_Change Jive Excel Worksheet Functions 2 June 11th 07 10:03 AM
Worksheet_Change scrimmy Excel Discussion (Misc queries) 7 April 26th 07 12:12 PM
Worksheet_change won't run Eric Excel Discussion (Misc queries) 4 March 10th 05 03:43 PM
worksheet_change vs. calculate, and worksheet_change not running Tom Ogilvy Excel Programming 1 July 14th 03 02:51 AM
worksheet_change vs. calculate, and worksheet_change not running Ross[_5_] Excel Programming 0 July 13th 03 04:27 PM


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