'將 a 轉成 1
function convertexcelnumtoint(colname as
string) as
integer
dim i as
integer
dim rtn as
integer
if len(colname) = 0 then
convertexcelnumtoint = 0
exit
function
endif
colname = ucase(colname)
rtn = 0
for i = 1 to len(colname)
rtn = rtn * 26
rtn = rtn + asc(mid(colname, i, 1)) - 64
next
convertexcelnumtoint = rtn
endfunction
'將 1 轉成 a
function converttoletter(icol as
integer) as
string
dim ialpha as
integer
dim iremainder as
integer
ialpha = fix(icol / 26)
iremainder = icol - (ialpha * 26)
if ialpha > 0 then
if iremainder = 0 then
ialpha = ialpha - 1
iremainder = 26
endif
if (ialpha > 0) then
converttoletter = chr(ialpha + 64)
endif
endif
if iremainder > 0 then
converttoletter = converttoletter & chr(iremainder + 64)
endif
endfunction
'取得autofilter的行號列表
function getautofilterresult(sh as worksheet) as vba.collection
dim rtn as
new vba.collection
dim curcell as range
countchange = worksheetfunction.subtotal(3, sh.autofilter.range)
if (countchange = sh.autofilter.range.columns.count) then
exit
function
endif
set curcell = sh.cells(sh.autofilter.range.row + 1, 1)
while
not isempty(curcell) ' check to see if row
' height is zero.
if curcell.rowheight > 0 then
rtn.add (curcell.row)
endif
set curcell = curcell.offset(1, 0)
wend
set getautofilterresult = rtn
endfunction
sub dictionarysample()
dim dic ' as new dictionary
dim d as
new vba.collection
d.add ("1")
d.remove (1)
set dic = createobject("scripting.dictionary")
dic.add "key", "dictionary"
s = dic.item("key")
'add(key,item) 增加鍵/條目對到 dictionary
'exists (key) 如果指定的鍵存在,返回 true,否則返回 false
'items() 返回乙個包含 dictionary 物件中所有條目的陣列
'keys() 返回乙個包含 dictionary 物件中所有鍵的陣列
'remove (key) 刪除乙個指定的鍵/條目對
'removeall() 刪除全部鍵/條目對
endsub
vba常用函式
1,vba 字串函式列表 trim string 去掉string左右兩端空白 ltrim string 去掉string左端空白 rtrim string 去掉string右端空白 len string 計算string長度 left string,x 取string左段x個字元組成的字串 rig...
VBA學習5 VBA常用函式
1,vba字串函式列表 trim string 去掉string左右兩端空白 ltrim string 去掉string左端空白 rtrim string 去掉string右端空白 len string 計算string長度 left string,x 取string左段x個字元組成的字串 righ...
M 常用EXCEL工作薄函式和VBA函式
match lookup value,lookup array,match type match 函式語法具有下列引數引數 為操作 事件 方法 屬性 函式或過程提供資訊的值。match type 行為1 或省略 match 查詢小於或等於 lookup value 的最大值。lookup array...