用VBA实现EXCEL公式的功能,谢谢!具体如图所示!

如题所述

这个看你VBA是否有些基础,有的话可以看懂下面的提示,没有的话...建议就用公式。

一般可以用双重循环来做:

dim i,j,k,ok,s1,s2
s1=range("b1")
for i=1 to 32
    s2=cells(i,1)
    ok=1
    for j=1 1 to len(s1)
        for k=1 to len(s2)
            if mid(s1,j,1)=mid(s2,k,1) then 
                ok=0
                exit for
            end if
        next k
        if ok=0 then exit for
    next j
    if ok=0 then cells(i,3)="x" else cells(i,3)="√"
next i

用数组可以更简洁和高效:

dim i,j,k,ok,s1,s2
dim arr(0 to 9) as boolean '每一位表示B1是否存在这个数字
s1=range("b1")
for j=1 to len(s1)
    arr(mid(s1,j,1)+0)=true
next j
for i=1 to 32
    s2=cells(i,1)
    ok=1
    for j=1 1 to len(s2)
        if arr(mid(s2,j,1)+0) then 
            ok=0
            exit for
        end if
    next j
    if ok=0 then cells(i,3)="x" else cells(i,3)="√"
next i追问

老师,我是因为用公式太卡了,才向你寻求vba的,还去赐教

数组比Vba还快速吗?

温馨提示:答案为网友推荐,仅供参考