vba-14 运算
'定义:运算符是代表VBA某种运算功能的符号?'1)赋值运算符:='2)数学运算符:&(字符连接符)、+(加)、-(减)、mod(取余)3 mod 4'4
'定义:运算符是代表VBA某种运算功能的符号?
'1)赋值运算符:=
'2)数学运算符:&(字符连接符)、+(加)、-(减)、mod(取余)3 mod 4'4/3、(整除)、*(乘)、/(除)、-(负号)、^(指数)
'3)逻辑运算符:not(非)、and(与)、or(或)、xor(亦或)、eqv(相等)、imp(隐含)
'4)关系运算符:=(相同)、<>(不等)、>(大于)、<(小于)、>=(不小于)、<=(不大于)、like
Sub mods()
Dim a%
a = 4 ^ 2
End Sub
'like 用来比较两个字符串
Sub likess()
Dim a
a = 1 Like "#"
End Sub
Sub likess1()
Dim a
a = "a" Like "[!abc]"
End Sub
'?任何单一字符
'*零个或多个字符
'#任何一个数字(0-9)
'[charlist]charlist.中的任何单一字符?
'[!charlist]不在charlist中的任何单一字符
Sub a1()
Dim a
a = "admin" Like "Admin" 'like区分大小写
End Sub
Sub a2()
Dim b, b2
b = "abc" Like "a?c" '通配符运用
b2 = "abcd" Like "????"
End Sub
Sub a3()
Dim c
c = "excel函数" Like "*函*"
End Sub
Sub a4()
Dim d
d = 88 Like "##"
End Sub
Sub a5()
Dim e, f, g
e = "f" Like "[a-z]"
f = 8 Like "[!1-8]"
g = 8 Like "[1-4,6-9]"
End Sub
Sub Sheet7()
Dim j, i, n
For j = 2 To 6 'sheet7中D2:D6
For i = 2 To 14 '2到14行
If Cells(i, "a") Like Cells(j, "d") Then n = n + 1 '比较Ai单元格与Dj单元格内容
Next
Range("e" & j) = n
n = 0
Next
End Sub
Sub 测试()
Dim rng As Range, rngs As Range, k%, a, b
For Each rng In [a2:a6]
a = rng.Value
For Each rngs In [b2:b4]
b = rngs.Value
If rng = rngs Then
GoTo 100
End If
Next rngs
k = k + 1
Cells(k + 1, "c") = rng
100:
Next rng
End Sub