• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Syntax problem in the SORT function

Hello the forum,
I need help to solve a problem of syntax in the SORT function in VBA.
I want to sort the contents of a spreadsheet based on a criterion selected from a dropdown list. The sequence of items in the list corresponds to the sequence of column headings.
So I set the column to sort by the statement:
Code:
ColToSort = wksh.Range(Cells (5, dd.ListIndex)
With
  • wksh = ActiveSheet
  • dd.ListIndex the rank of the selection in the drop down list = column heading.
  • 5 = the row containing the column headings.
When I specify the "Key:= Range" in
Code:
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:= Range (ColToSort) _
SortOn: = xlSortOnValues​​, Order: = xlAscending, DataOption: = xlSortNormal
A message "Method 'Range' of object '_Global' failed" appears.
By cons, if I write
Code:
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key: = Range ("C5"), _
SortOn: = xlSortOnValues​​, Order: = xlAscending, DataOption: = xlSortNormal
No error appears.
Could a member of the forum advice me on how to write the variable ColToSort.
Thanks in advance

Harry
 
Hallo Debraj,
In the referenced link I found the solution on my syntax problem.
Just add .adress for the variable ColToSort.
I saw also that you where learning french. So I conclude this thread with
Grand merci pour la réponse pertinente.
Have a nice day

Harry
 
@Marc L
Salut!
Toujours... eh bien, vous n'avez pas réalisé qui Debraj(ex-Roy) il suit mes traces?
Cordialement!
PS: Pas seulement le Français, j'ai lu de plusieus langues asiatiques aussi, un peu d'espagnol, ... urbi et orbi)

(Hi!
Always... well, haven't you realized yet that Debraj(ex-Roy) follows my footsteps?
Regards!
PS: Not only French, I've read many Asian languages too, a bit of Spanish, ... urbi et orbi)

@Debraj(ex-Roy)
Hi, foreigner!
Haven't you noticed yet that if you write in a language other than English -and only exceptionally- you should provide the English translation as well? And it was you whom I read in other exotic (for me) idioms... so this shouldn't be the 1st time I write something alike, is it?
Regards!
PS: If required :confused: you could ask a Ninja ;) or a staff :p member how to proceed... :D :oops: o_O
 
Back
Top