View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
oms oms is offline
external usenet poster
 
Posts: 3
Default Worksheet_Change - initiate macro on another worksheet

I am trying to get excel to automatically run a macro based off a change in
any cell in a column. I've been trying worksheet_change but have not had
much luck.

Objective:
If there is a change to any of the cells in column G of Sheet 1 (cell
contains a formula that works off other cells), I want the macro to sort data
on Sheet 2 (info that I linked from Sheet 1). I am unhiding and hiding a
column in Sheet 2 because it contains the value that I'm sorting by but I
don't want it to show in the final product.

I've attached the code below. Thanks in advance.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("G3:G110")) Is Nothing Then

Application.EnableEvents = False
Application.ScreenUpdating = False
On Error Resume Next

Sheets("Sheet 2").Select

'Unhide Column C
Columns("B:D").Select
Selection.EntireColumn.Hidden = False

'Sort based on Column C value
Range("C2").Select
Range("A1:C50").Sort Key1:=Range("C2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'Hide Column C
Columns("C:C").Select
Selection.EntireColumn.Hidden = True

End If

Application.EnableEvents = True
Application.ScreenUpdating = True
On Error GoTo 0

Sheets("Sheet 1").Select

End Sub