VBA直接数组中用if比较要如何写
++++://pan.baidu.com/s/1miRhgSC 把++++改成http就可以
VBA直接数组中用if比较要如何写
答案:2 悬赏:70 手机版
解决时间 2021-04-11 17:34
- 提问者网友:听门外雪花风
- 2021-04-10 17:29
最佳答案
- 五星知识达人网友:走死在岁月里
- 2021-04-10 18:39
'数组的话其实就是在两个循环中对比,字典法最容易理解
Sub 用if比较() 'VBA只用if在数组中比较要如何写,只写了一半没有写完请高手指导
Dim txt As String 'if比较结果保存A4单元格
txt = Cells(1, 1)
Dim arr() As String
Dim arrr() As String
Dim b As Boolean
arr = Split(txt, ",")
n = UBound(arr)
For i = 0 To n
b = False
For j = 0 To i - 1
If arr(j) = arr(i) Then b = True: Exit For
Next
If Not b Then
ReDim Preserve arrr(m)
arrr(m) = arr(i)
m = m + 1
End If
Next
Sheet9.Range("a4") = Join(arrr, ",")
End Sub
Sub 用if比较() 'VBA只用if在数组中比较要如何写,只写了一半没有写完请高手指导
Dim txt As String 'if比较结果保存A4单元格
txt = Cells(1, 1)
Dim arr() As String
Dim arrr() As String
Dim b As Boolean
arr = Split(txt, ",")
n = UBound(arr)
For i = 0 To n
b = False
For j = 0 To i - 1
If arr(j) = arr(i) Then b = True: Exit For
Next
If Not b Then
ReDim Preserve arrr(m)
arrr(m) = arr(i)
m = m + 1
End If
Next
Sheet9.Range("a4") = Join(arrr, ",")
End Sub
全部回答
- 1楼网友:怀裏藏嬌
- 2021-04-10 20:05
你的arr数组,本是一维数组,不需要转置。
只有arr=range("a1:a" & m).value 得来的才是二维的,但是转置以后还是二维的。
用循环,用range也是可以的
for j for j =2 to 10 step 2
sheets("0" & aaa).cells(8,i)=brr(i)
for j =2 to 10 step 2
sheets("0" & aaa).range("b8").offset(0,j-2)=arr(j/2)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯