I have a table in excel that updates automatically (or manually) by pulling from a website.
I have another table that is linked, that I want to sort automatically every time the data is updated. Any way to do this?
preguntado el 09 de marzo de 12 a las 14:03
In the Sheet where the table that needs to update automatically is located, you can add something like the code below (pseudo code) - it will sort the table every time is is changed. Note that it might get slow if you get frequent updates.
Private Sub Worksheet_Change(ByVal Target As Range) If Target is in the table (you can check Target.Row and Target.Column for example) Then Sort the table End If End Sub
If the range is a named range called named_range you can do this for example (not very efficient but readable):
Private Sub Worksheet_Change(ByVal Target As Range) For Each c In [named_range] If c = Target Then MsgBox "OK" Next c End Sub
Or you can do this, which will perform better is the named range is large:
Private Sub Worksheet_Change(ByVal Target As Range) Dim row_start As Long Dim row_end As Long Dim col_start As Long Dim col_end As Long row_start = [named_range].Cells(1, 1).Row col_start = [named_range].Cells(1, 1).Column row_end = row_start + [named_range].Rows.Count - 1 col_end = col_start + [named_range].Columns.Count - 1 If Target.Row >= row_start And Target.Row <= row_end And Target.Column >= col_start And Target.Column <= col_end Then MsgBox "In range" End If End Sub