我想计算数组txt中“c”的数字。 1到0的过渡意味着一个新的循环,这就是为什么当这种情况发生时,我会放一个“c”。在这段代码中,当我尝试计算“c”时,出现类型不匹配。感谢您的帮助。识别和计算数组中相同值的元素Excel VBA
Sub CopyColumn()
Dim finalrow As Long
Dim i As Variant
ReDim arrayciclos(0)
Dim str As String
Dim ciclos As Variant
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To finalrow
arrayciclos(UBound(arrayciclos)) = Range("J" & i)
ReDim Preserve arrayciclos(UBound(arrayciclos) + 1)
Next i
For i = LBound(arrayciclos) To UBound(arrayciclos)
txt = txt & arrayciclos(i) ' & vbCrLf
Next i
MsgBox txt
Do While InStr(txt, "10")
txt = Replace(txt, "10", "c")
Loop
MsgBox txt
ciclos = 0: i = 0
For i = 0 To finalrow
If txt(i) = "c" Then ' i have Type Mismatch here
ciclos = ciclos + 1
End If
Next
MsgBox (ciclos)
End Sub
我不检查的代码,但** ** TXT它不是一个数组,你可以不写** TXT(I)** ...... – user3514930 2014-09-23 11:40:06