我是VBA的新手,因此遇到此问题。 表的位置和值
A1 S+01a
A2 S+02a
A3 S+03a
A4 S-01a
A5 S-01b
A6 S-02a
因为这是由VBA生成的,所以我想以此顺序订购
A1 S+01a
A2 S-01a
A3 S-01b
A4 S+02a
A5 S-02b
A6 S+03a
排序规则为
我想通过VBA执行此操作(因为数据长度会更大) 这种情况有什么线索吗?
谢谢您的回答/提示。
答案 0 :(得分:2)
由于我不确定您的代码如何处理数组(或集合),并且您没有向我展示实际的代码,因此我编写了此POC,但是它的编码很差。 基本上,我对字符串进行编码解码,以优先考虑您的排序标准(包括+和-号)。
Sub test()
Dim array_unsorted(1 To 6) As String
Dim i As Long
Dim recoded(1 To 6) As String
Dim temp As String
Dim target As String
array_unsorted(1) = "S+01a"
array_unsorted(2) = "S+02a"
array_unsorted(3) = "S+03a"
array_unsorted(4) = "S-01a"
array_unsorted(5) = "S-01b"
array_unsorted(6) = "S-02a"
For i = 1 To 6
target = array_unsorted(i)
temp = Replace(target, "+", "A")
temp = Replace(target, "-", "Z")
recoded(i) = Mid(temp, 3, 2) & Right(temp, 1) & target
Next
Call QuickSort(recoded, 1, 6)
For i = 1 To 6
s = Right(recoded(i), 5)
Debug.Print s
Next
End Sub
Public Sub QuickSort(ByRef vArray As Variant, inLow As Long, inHi As Long)
Dim pivot As Variant
Dim tmpSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
While (tmpLow <= tmpHi)
While (vArray(tmpLow) < pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Wend
While (pivot < vArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow < tmpHi) Then QuickSort vArray, inLow, tmpHi
If (tmpLow < inHi) Then QuickSort vArray, tmpLow, inHi
End Sub
至少它有效,并且可能是一个起点。快乐的编码。 干杯!
答案 1 :(得分:1)
try{
//send request
}
catch (DocuSign\eSign\ApiException $ex){
print_R($ex); //<--- print normal readeble error
echo "Exception: " . $ex->getMessage() . "\n";
}
功能区选项卡上,单击Data
Sort
下拉菜单,然后在列表底部选择Order
。这将带您进入自定义排序对话框,您可以在其中添加特定的排序顺序,然后将其保留在列表中。
另请参阅:Sort data using a custom list
如果有特定原因必须通过VBA完成,我建议Recording a Macro to Generate Code,然后您可以revise it as required。