Hi,
I'm fairly new to VBA but I'm using a userform to enter data into a table on another sheet, opening the userform through a simple
Sub OpenUserform()
'
' OpenUserform Macro
' Opens the Data Table Userform
ActiveSheet.Cells(1, 1).Select
Sheets("Clinics Data Table").ShowDataForm
End Sub
When closing the data entry form, I want to call a macro that autosorts a specific column in my data table.
Right now I created this Macro to autosort my table:
Sub SortDataTableByIDNumber()
'
' SortDataTableByIDNumber Macro
'
ActiveWorkbook.Worksheets("Clinics Data Table").ListObjects("Clinics").Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("Clinics Data Table").ListObjects("Clinics").Sort. _
SortFields.Add Key:=Range("Clinics[[#All],[ID '#]]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Clinics Data Table").ListObjects("Clinics"). _
Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
and then trying to call that Macro through a WorkSheet_Change macro
Sub WorkSheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("Clinics[[#All],[ID '#]]"), Range(Target.Address)) Is Nothing Then
Call SortDataTableByIDNumber
End If
End Sub
But changing data and closing the DataForm doesn't trigger the two other Macro's.
I've read that all macro's are stopped when opening a DataForm, but how do I get the macro's to trigger so the specified cells will be sorted if there is changes in the data?
Bookmarks