1. 輸入和絕對值
sub qingwuabs()
dim a, b as integer
a = inputbox("請輸入乙個負數:", "提示")
b = abs(a)
msgbox "你輸入數的絕對值為:" & b
end sub
2. if結構
sub testif()
[a1] = 35
if [a1] > 30 then
msgbox ">30"
else
msgbox "<=30"
end if
end sub
3. select結構
sub testselect()
[a2] = 40
select case [a2].value
case is < 30
msgbox "<30"
case is < 60
msgbox "<60"
case is < 80
msgbox "<80"
case else
msgbox "優秀"
end select
end sub
4. 迴圈for
sub testloop()
dim lsum as long, i as long
for i = 1 to 100 step 1 'step 可省略
lsum = lsum + i
next i 'next 亦可
msgbox "1到1000的自然數和為:" & lsum
end sub
5. for each
sub testforeach()
dim i as integer, sht as worksheet
i = 1
for each sht in worksheets
cells(i, 1) = sht.name
i = i + 1
next
end sub
6. do while
sub testdowhile()
dim lsum as long, i as long
i = 1
do while i <= 1000
lsum = lsum + i
i = i + 1
loop
msgbox lsum
end sub
7. do until
sub testdountil()
dim lsum as long, i as long
i = 1
dolsum = lsum + i
i = i + 1
loop until i > 1000
msgbox lsum
end sub
0
給主人留下些什麼吧!~~
Office Excel VBA程式設計
本文涉及到的內容包括vba陣列 從單元格讀取值填充二維陣列 取excel檔案的有效行 多檔案合併等內容。首先,有檔案1 檔案2 檔案3,檔案1的名字為 合併.xls 檔案2 檔案3等的檔名隨意定。但他們的格式需要一致,如下圖所示 現在,把檔案2 檔案3的內容合併到合併.xls檔案中。由於檔案2 檔案...
學做事,先學做人
經理很關照我,我很感謝經理。其實,有乙個好的領導,只要好好幹,他是一定會知道的。但是,要改變客戶的看法,看來還真的很難。在客戶面前不可以太謙虛,太過謙虛,他們反覺得我們無能。做事先做人,一點都沒錯啊。感覺自己太嫩了,這一切還得慢慢磨練。希望多看數,多學習,多仔細觀察生活,觀察周圍成功的人,不斷提高自...
B 學密碼學真的得學程式
b 學密碼學真的得學程式 time limit 1000msmemory limit 65536kb64bit io format lld llu submit status practice sdutoj 2464 description 話說,上次zyj同學最終在眾位瑪麗亞的幫助下搞定了那個神奇...