1

I have the following code

Sub Test()
    Dim x
    x = "ow, bv, xz"
    With ActiveSheet.Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("D1"), CustomOrder:=x
        .SortFields.Add Key:=Range("C1"), Order:=xlDescending
        .SortFields.Add Key:=Range("B1"), Order:=xlAscending
        .SetRange Range("A1").CurrentRegion
        .Header = xlYes
        .Apply
    End With
End Sub

I tried to use CustomOrder and assign a variable x to the string. When using the string directly, it works well but not with using variable Any idea how to fix that?

YasserKhalil
  • 9,138
  • 7
  • 36
  • 95

1 Answers1

1

Seems like a bug. The following work for me:

CustomOrder:=Cstr(x)
CustomOrder:=Join(Split(x)) 'overkill, but for laughs
CustomOrder:=x & vbNullString
BigBen
  • 46,229
  • 7
  • 24
  • 40