VBA中的变量不会更改

时间:2017-07-10 23:15:04

标签: excel vba excel-vba

我正在尝试使用表格中的某些信息创建一个新表 像这样的结构:

A    B    D   G  L
A    B    D   G  M
A    B    D   H  N
A    B    E   I  O
A    C    F   J  P
A    C    F   K  Q

因此,它返回一个包含如下行的表:

A  |  D |  B |  "G: L M   H: N"

原始数据库包含以下列:

  • 作用
  • 对象
  • 实例
  • 字段

新表应该是:Role,Instance,Object,Object value。因此,如果对象是相同的,则意味着它是该对象的新实例,它的新值将是每个字段(包含所有值),如上例所示。

这是代码(文本应该在前5列中,它应该从G列返回):

Sub instancia()

Dim fila, filacol As Long

Dim cad, c As String

fila = 2
filacol = 2

Do
    cad = ""

    Cells(filacol, 7) = Cells(fila, 1)
    Cells(filacol, 8) = Cells(fila, 3)
    Cells(filacol, 9) = Cells(fila, 2)

    Do
        c = " "
        cad = cad + Cells(fila, 4).Value + ": "
        Do
            c = c + Cells(fila, 5).Value + " "
            fila = fila + 1
        Loop While Cells(fila, 4) = Cells(fila + 1, 4)

        cad = cad + c
    Loop While Cells(fila, 2).Value = Cells(fila + 1, 2).Value
    Cells(filacol, 10).Value = car
    filacol = filacol + 1

Loop While Cells(fila + 1, 2) <> Empty

End Sub

它没有用,因为它说执行时间有问题,但是试图调试,我发现变量'fila'永远不会改变。我该怎么办?

0 个答案:

没有答案