我正在尝试设置代码来读取列中的一系列数字并返回指定的较短数字。例如,如果数字是200,那么这将返回数字1,而400将返回2.如果可能,是否有任何想法?
答案 0 :(得分:0)
这是一个带有双循环的小例子:
Sub Shorten()
Dim ary(1 To 4) As Long, bry(1 To 4) As Long
Dim I As Long, N As Long
ary(1) = 100
ary(2) = 234
ary(3) = 8765
ary(4) = 123
bry(1) = 1
bry(2) = 2
bry(3) = 3
bry(4) = 4
N = Cells(Rows.Count, "A").End(xlUp).Row
For I = 1 To N
For j = 1 To 4
If Cells(I, 1).Value = ary(j) Then Cells(I, 1).Value = bry(j)
Next j
Next I
End Sub
ary()包含“long”值列表,bry()包含“short”值列表。