Sorting Master Data Services (MDS) entity table with VBA

StringKing

New Member
Joined
Jul 22, 2009
Messages
21
Good day,

I am trying to sort a table that updates from Master Data Services add-in on Excel, by using VBA.

I cannot reference the table (ListObject) name, as the name might change everytime the table gets updated when a connection is established.
The name of the sheet on which the table is is also variable and can also change everytime someone establishes a connection on the MDS sheet.

I have tried sorting using the sheet and listobject names, as well as referring to it at Sheets(1).ListObject(1).

When stepping through the code in break mode (F8) the VBA executes perfectly, but when running the code (F5) it does not execute the sort. :confused:

Please help so that I can execute the macro without having to step through it in break mode and in order for me to add the rest of the VBA code to complete the remainder of the requirement.

'--__--__--__--__--__--__--__--__--__--

Sub SortNoRange()


Dim Ws As Worksheet
Dim LR As Long


'Sort MDS data
Sheets(1).Activate


Set Ws = ActiveSheet
LR = Ws.Range("A" & Rows.Count).End(xlUp).Row


Ws.Sort.SortFields.Clear
Ws.Sort.SortFields.Add Key:=Range("X3:X" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With Ws.Sort
.SetRange Range("A3:X" & LR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End Sub

'--__--__--__--__--__--__--__--__--__--
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Unfortunately I cannot supply the Excel workbook, but see below screen snip:
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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