我有一个数据列表,在3列上以非同类模式分发。挑战是写一个vba代码"足够聪明"将所有这些数字复制并粘贴到一列上,将它们按顺序排列,一列低于另一列:1,2,3,4,4.1,4.2等。不会错过任何一个。
有人可以帮我完成这项任务吗?因为我看到了很多复杂性,我不知道如何管理它。谢谢!
答案 0 :(得分:1)
据我所知,您希望以特定的方式订购,而且默认情况下Excel不会排序。值看起来像版本号或嵌套的任务ID。
Stack Overflow并非真正为您解决问题"那种地方,但我绝对可以让你开始。以下是您需要做的事情:
'Converts 1 => 001000000000
' 1.1 => 001001000000
' 2.4.7 => 002004007000
' 65.339.1 => 065339001000
Function ConvertToSortableVersionNumber(value As String) As String
'Add all the parts of the value (. delimited) to a collection
Dim vnPart As Variant
Dim error As Boolean: error = False
Dim Parts As Collection
Set Parts = New Collection
For Each vnPart In Split(value, ".")
'Make sure this can actually be formatted as needed.
If Len(vnPart) > 3 Then
error = True
Exit For
End If
'Add this part to the Parts collection
Parts.Add vnPart
Next vnPart
'Now make sure there are 4 parts total
If Parts.Count > 4 Then error = True
'Check for errors
If error Then
'There is an error. Handle it somehow
End If
'If there are less than 4 items in the collection , add some
While Parts.Count < 4
Parts.Add ("000")
Wend
'Now, assemble the return value
Dim retVal As String
Dim item As Variant
For Each item In Parts
retVal = retVal & Right(String(3, "0") & item, 3)
Next item
'All set!
ConvertToSortableVersionNumber = retVal
End Function
捅一下。我想你一旦发现你已经完成的工作,你已经尝试过的,以及具体给你带来麻烦的东西,你会发现Stack Overflow会更有帮助。
祝你好运!答案 1 :(得分:0)
如果你有2010年或以后,下面的公式将会这样做:
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/usr/lib/cgi-bin/mongo/2.2.3/dbparse.py in ()
41 print "</th>"
42 if where:
=> 43 for record in collection.find(where):
44 print "<tr>"
45 print "<td align=\"center\">"+record["test"]+"</td>"
record undefined, collection = Collection(Database(MongoClient('localhost', 27017), u'test_d'), u'london_garages'), collection.find = <bound method Collection.find of Collection(Data...', 27017), u'test_d'), u'l_g')>, where = {'$where': "this.test== ''--'"}
如果您有2007年或更早版本,那么它需要是一个数组公式:
=IFERROR(SUBSTITUTE(SUBSTITUTE(AGGREGATE(15,6,--SUBSTITUTE($A$1:$C$10,".","000")*--(1 & REPT("0",9-LEN(SUBSTITUTE($A$1:$C$10,".","000")))),ROW(1:1)),"0000",""),"000","."),"")
作为数组公式,必须在退出编辑模式时使用Ctrl-Shift-Enter而不是Enter确认。
E列是第一个公式,F列是第二个公式。