Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Trying to get a macro to run when cell selection changes.

I have a workbook with two worksheets, each one with a table and I'm trying
to get a macro to run that filters the the second worksheet table with the
value of the the cell selected in column A of the first worksheet. After
getting some hints here on this forum I came up with:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Windows("Inventory Items.xlsm:1").Activate

If ActiveCell.Column = 1 Then
Dim ItemNum As String
ItemNum = "=" & ActiveCell.Text
Windows("Inventory Items.xlsm:2").Activate
ActiveSheet.ListObjects("Table_Default__ipurch").R ange.AutoFilter
Field:=1, _
Criteria1:=ItemNum, Operator:=xlAnd
Windows("Inventory Items.xlsm:2").Activate
End If
End Sub

but it doesn't work automatically when I select another cell (in the first
column)even though it runs perfectly when I run it manually with the first
line changed to:

Sub FilterPurchases()

How does one get it to run automatically when the selection changes?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Trying to get a macro to run when cell selection changes.

Did you put it in the worksheet code module? The worksheet_selctionchange
will not work from the standard code Module1. You must right click the name
tab of the active sheet, then click View Code from the drop down menu. That
opens the sheet code module. Paste your code there and then try it.

"Bob Arnett" wrote:

I have a workbook with two worksheets, each one with a table and I'm trying
to get a macro to run that filters the the second worksheet table with the
value of the the cell selected in column A of the first worksheet. After
getting some hints here on this forum I came up with:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Windows("Inventory Items.xlsm:1").Activate

If ActiveCell.Column = 1 Then
Dim ItemNum As String
ItemNum = "=" & ActiveCell.Text
Windows("Inventory Items.xlsm:2").Activate
ActiveSheet.ListObjects("Table_Default__ipurch").R ange.AutoFilter
Field:=1, _
Criteria1:=ItemNum, Operator:=xlAnd
Windows("Inventory Items.xlsm:2").Activate
End If
End Sub

but it doesn't work automatically when I select another cell (in the first
column)even though it runs perfectly when I run it manually with the first
line changed to:

Sub FilterPurchases()

How does one get it to run automatically when the selection changes?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Trying to get a macro to run when cell selection changes.

Excellent. I was just in the wrong place.

"JLGWhiz" wrote:

Did you put it in the worksheet code module? The worksheet_selctionchange
will not work from the standard code Module1. You must right click the name
tab of the active sheet, then click View Code from the drop down menu. That
opens the sheet code module. Paste your code there and then try it.

"Bob Arnett" wrote:

I have a workbook with two worksheets, each one with a table and I'm trying
to get a macro to run that filters the the second worksheet table with the
value of the the cell selected in column A of the first worksheet. After
getting some hints here on this forum I came up with:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Windows("Inventory Items.xlsm:1").Activate

If ActiveCell.Column = 1 Then
Dim ItemNum As String
ItemNum = "=" & ActiveCell.Text
Windows("Inventory Items.xlsm:2").Activate
ActiveSheet.ListObjects("Table_Default__ipurch").R ange.AutoFilter
Field:=1, _
Criteria1:=ItemNum, Operator:=xlAnd
Windows("Inventory Items.xlsm:2").Activate
End If
End Sub

but it doesn't work automatically when I select another cell (in the first
column)even though it runs perfectly when I run it manually with the first
line changed to:

Sub FilterPurchases()

How does one get it to run automatically when the selection changes?

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 do you move the selection one cell to the right in a macro fder Excel Programming 3 May 11th 06 06:51 PM
Macro - Dynamic cell selection Chris Excel Discussion (Misc queries) 1 January 11th 06 01:48 PM
Macro help on Cell Selection Nigel Excel Programming 3 April 27th 05 12:26 PM
Cell selection in a macro GatheringShadow[_2_] Excel Programming 0 October 21st 04 01:45 PM
Cell selection in a macro GatheringShadow Excel Programming 2 October 21st 04 12:33 AM


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