beat365官网下载苹果手机-365bet备用服务器-bt365投注

记录时光的故事

VBA like和通配符

分类: bt365投注 时间: 2025-07-20 15:20:11 作者: admin 阅读: 4697
VBA like和通配符

Next

Stay

AutoMacro - VBA 代码生成器

学到更多

使用 [char list] 作为通配符

The example above can be modified slightly to allow us to use the question mark, in addition to a character list of allowed characters. The wildcard string can therefore be amended to “?[e-i]m” where the first character can be anything, the second character has to be a character between e and i and the last letter has to be the character “m”. Only 3 characters are allowed.

1

2

3

4

5

6

7

8

SubCharListTest()

DimxAsInteger

Forx=3To8

IfRange("B"&x).Value Like"?[e-i]m"Then

Range("B"&x).Font.Color=vbRed

EndIf

Nextx

EndSub

The result of this code would be:

Using the hash (#) Wildcard in VBA

The hash (#) wildcard replaces a single digit in a VBA string. We can match between 0 to 9.

1

2

3

4

5

6

7

8

9

10

SubCheckForNumber()

DimxAsInteger,yAsInteger

Forx=3To8

Fory=2To5

IfActiveSheet.Cells(x,y)Like"##"Then

ActiveSheet.Cells(x,y).Font.Color=vbRed

EndIf

Nexty

Nextx

EndSub

The code above will loop through all the cells in the Range (“B3:E8”) and will change the color of the text in a cell to RED if a double-digit number is found in that cell.

In the example below, the code will only change the number if the last number is a 9.

1

2

3

4

5

6

7

8

9

10

SubCheckFor9()

DimxAsInteger,yAsInteger

Forx=3To8

Fory=2To5

IfActiveSheet.Cells(x,y)Like"#9"Then

ActiveSheet.Cells(x,y).Font.Color=vbRed

EndIf

Nexty

Nextx

EndSub

相关文章

dnf贪食首饰换哪个
娱的成语
《英雄联盟》S15最新史诗野怪刷新时间
古城荆棘王
2025十大免费漫画软件推荐
三星w2014评测(三星w2014好在哪里为啥这么贵)