微信小国旗-task

ubound
2023年4月3日发(作者:英伟达显卡驱动下载)

使⽤VBA提取字符

Sub字符提取()

Dims,x,arr,arr2()

'将A2到A列最末⾏的单元格区域赋给数组arr

arr=Range('a2:a'&Cells(,1).End(3).Row)

ReDimarr2(1ToUBound(arr))'重新定义数组arr2⼤⼩

Forx=1ToUBound(arr)'建⽴循环

s=Split(arr(x,1),',')'⽤逗号拆分数组,返回⼀个下标从零开始的⼀维数组

Bound(s)'结果为3

arr2(x)=s(UBound(s)-1)'为数组arr2赋值,提取第2个第3个逗号之间的内容

'arr2(x)=s(UBound(s))'提取最后⼀个逗号之后的内容

'arr2(x)=s(UBound(s)-1)'提取第2个第3个逗号之间的内容

'arr2(x)=s(UBound(s)-2)'提取第1个第2个逗号之间的内容

'arr2(x)=s(UBound(s)-3)'提取第1个逗号之前的内容

Nextx

Range('b2:b'&UBound(arr)).ClearContents'清空单元格内容

Range('b2').Resize(UBound(arr))=ose(arr2)'将数组arr2转置为纵向后

填⼊B2向下的区域中

EndSub

更多推荐

ubound