相关疑难解决方法(0)

vba:从数组中获取唯一值

在vba中有内置的功能来从一维数组中获取唯一值吗?怎么样才能摆脱重复?

如果没有,那么我如何从数组中获取唯一值?

excel vba excel-vba

46
推荐指数
3
解决办法
17万
查看次数

Dir()是否对退回的文件的顺序做出任何保证?

我正在尝试清理一些现有的代码

Sheets("Control").Select
MyDir = Cells(2, 1)
CopySheet = Cells(6, 2)
MyFileName = Dir(MyDir & "wp*.xls")

' when the loop breaks, we know that any subsequent call to Dir implies
' that the file need to be added to the list
While MyFileName <> LastFileName
    MyFileName = Dir
Wend

MyFileName = Dir

While MyFileName <> ""
    Cells(LastRow + 1, 1) = MyFileName
    LastRow = LastRow + 1
    MyFileName = Dir
Wend
Run Code Online (Sandbox Code Playgroud)

我的问题涉及Dir退货结果以及结果顺序是否有任何保证.当Dir在上面的循环中使用时,代码暗示结果调用Dir按名称排序.

除非Dir保证这一点,否则这是一个需要修复的错误.问题是,Dir()是否对返回文件的顺序做出了任何保证,还是隐含的? …

excel vba

13
推荐指数
1
解决办法
1万
查看次数

在VBA中对多维数组进行排序

我已经定义了以下数组Dim myArray(10,5) as Long并希望对其进行排序.最好的方法是什么?

我将需要处理大量数据,如1000 x 5矩阵.它主要包含数字和日期,需要根据某列进行排序

arrays sorting vba

12
推荐指数
2
解决办法
7万
查看次数

Excel vba按字母顺序循环显示范围

我想按字母顺序循环一系列单元格,以按字母顺序创建报表.由于原始订单很重要,我不想对工作表进行排序.

Sub AlphaLoop()

'This is showing N and Z in uppercase, why?
For Each FirstLetter In Array(a, b, c, d, e, f, g, h, i, j, k, l, m, N, o, p, q, r, s, t, u, v, w, x, y, Z)
    For Each SecondLetter In Array(a, b, c, d, e, f, g, h, i, j, k, l, m, N, o, p, q, r, s, t, u, v, w, x, y, Z)
        For Each tCell In Range("I5:I" & Range("I20000").End(xlUp).Row)
            If …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

5
推荐指数
1
解决办法
2859
查看次数

在VBA中排序数组

我有一个182.123大小的数组,我想通过数组类的特定属性对它们进行排序.该类被称为CFlujo,我想要对它们进行排序的属性是一个名为id_flujo的字符串.到目前为止,我正在做这样的冒泡,但它只需要太长时间:

Sub sort_arreglo(arreglo As Variant)
For x = LBound(arreglo) To UBound(arreglo)
For y = x To UBound(arreglo)
    Dim aux As CFlujo
    aux = New CFlujo
  If UCase(arreglo(y).id_flujo) < UCase(arreglo(x).id_flujo) Then
    Set aux = arreglo(y)
    Set arreglo(y) = arreglo(x)
    Set arreglo(x) = aux
  End If
 Next y
Next x
End Sub
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经研究了选择排序,但我知道你不能从数组中删除项目,所以我不能制作两个列表来将值从一个排序到另一个.我可以将我的数据放入集合中,但我在数据质量方面遇到了麻烦,除非我预先分配内存(比如在数组中).

sorting excel vba excel-vba

5
推荐指数
1
解决办法
4761
查看次数

用于排序和过滤的数据结构

是否有任何数据结构可以通过有效的对象排序和过滤来访问?

对于排序,这System.Collections.ArrayList是完美的,因为我只是添加了大量的类 whichImplement IComparable.Sort(). 但是我找不到.Filter()方法,因为可能存在一些文章提示(第 9.3 节)。

是否有用于过滤和排序自定义对象的良好集合类型?最好是用预编译语言编写的东西。


一个简单的对象看起来像这样:

Implements IComparable                           'requires mscorlib.dll, allows sorting

Public itemIndex As Long                        'simplest, sorting by an integer value

Private Function IComparable_CompareTo(ByVal obj As Variant) As Long
    'for sorting, itemindex is based on current grid sorting mode
    If TypeOf obj Is clsGridItem Then
        Dim other As clsGridItem: Set other = obj
        Dim otherIndex As Long: otherIndex = other.itemIndex
        Dim thisIndex As Long: thisIndex = …
Run Code Online (Sandbox Code Playgroud)

sorting collections excel vba arraylist

4
推荐指数
1
解决办法
519
查看次数

excel:我如何在一个单元格内排序?

我有一个用逗号分隔的字符串,是否可以使用excel公式在单元格内的值内进行排序?

excel

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

excel ×6

vba ×6

excel-vba ×3

sorting ×3

arraylist ×1

arrays ×1

collections ×1