Run macro when cell changes - not working

alexbat

New Member
Joined
Dec 12, 2013
Messages
32
Hi,

quite new to VB. I try to run a script when any of the cells in a range changes with the following code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B5:F5")) Is Nothing Then
    Application.ScreenUpdating = False
    Sheets("Overdue data").Select
    ActiveWindow.SmallScroll Down:=-12
    Range("J27:Q27").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("H22").Select
    ActiveWorkbook.Worksheets("Overdue data").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Overdue data").Sort.SortFields.Add Key:=Range( _
        "H20:H1314"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Overdue data").Sort
        .SetRange Range("B19:I1314")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("B19:I3000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
        Range("D1:F4"), CopyToRange:=Range("J27:Q27"), Unique:=False
    Sheets("Overdues").Select
    ActiveWindow.SmallScroll Down:=-18
    Application.ScreenUpdating = True
    
End If
End Sub

I don't get it to work, it stops at line

Range("J27:Q27").Select


What am I doing wrong??
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
When code is in a Worksheet module, unqualified properties refer to the worksheet that contains the code rather than the active sheet as is the case for code in a General module. So you need:

Rich (BB code):
ActiveSheet.Range("J27:Q27").Select
 
Upvote 0
Andrew,

the script works now, but not as I intended... :confused:

I put the code in the sheet "Dashboard" where the users can do some choices in cells B5:F5. These changes should trigg some sorting and filering in sheet "Overdue data".
It seems that the script performs actions within the sheet "Dashboard" and not "Overdue data" as I want it to.
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top