EXCEL常用巨集大全

2022-09-25 07:54:02 字數 4811 閱讀 2028

開啟全部隱藏工作表

sub 開啟全部隱藏工作表()

dim i as integer

for i = 1 to

sheets(i).visible = true

next i

end sub

迴圈巨集sub 迴圈()

aaa = range(「c2″)

dim i as long

dim times as long

times = aaa

『times代表迴圈次數,執行前把times賦值即可(不可小於1,不可大於2147483647)

for i = 1 to times

call 過濾一行

if range(「完成標誌」) = 「完成」 then exit for 『如果名為』完成標誌』的命名單元的值等於』完成』,則退出迴圈,如果一開始就等於』完成』,則只執行一次迴圈就退出

『if sheets(「傳送引數」).range(「a」 & i).text = 「完成」 then exit for 』如果某列出現」完成」內容則退出迴圈

next i

end sub

錄製巨集時呼叫「停止錄製」工具欄

sub 錄製巨集時呼叫停止錄製工具欄()

recording」).visible = true

end sub

高階篩選5列不重複資料至指定表

sub 高階篩選5列不重複資料至sheet2()

sheets(「sheet2″).range(「a1:e65536″) = 「」 『清除sheet2的a:d列

range(「a1:e65536″).advancedfilter action:=xlfiltercopy, copytorange:= _

「a1″), unique:=true

key1:= order1:=xlascending, header:=xlguess, _

ordercustom:=1, matchcase:=false, orientation:=xltoptobottom, sortmethod _

xlpinyin

end sub

雙擊單元執行巨集(工作表**)

private sub worksheet_beforedoubleclick(byval target as range, cancel as boolean)

if range(「$a$1″) = 「關閉」 then exit sub

select case

case 「$a$4″

call 巨集1

cancel = true

case 「$b$4″

call 巨集2

cancel = true

case 「$c$4″

call 巨集3

cancel = true

case 「$e$4″

call 巨集4

cancel = true

end select

end sub

雙擊指定區域單元執行巨集(工作表**)

private sub worksheet_beforedoubleclick(byval target as range, cancel as boolean)

if range(「$a$1″) = 「關閉」 then exit sub

if not range(「a4:a9″, 「c4:c9″)) is nothing then call 開啟隱藏表

end sub

進入單元執行巨集(工作表**)

private sub worksheet_selectionchange(byval target as range)

『以單元格進入代替按鈕物件呼叫巨集

if range(「$a$1″) = 「關閉」 then exit sub

select case

case 「$a$5″ 『單元位址(或命名單元名字(

call 巨集1

case 「$b$5″

call 巨集2

case 「$c$5″

call 巨集3

end select

end sub

進入指定區域單元執行巨集(工作表**)

private sub worksheet_selectionchange(byval target as range)

if range(「$a$1″) = 「關閉」 then exit sub

if not range(「a4:a9″,」c4:c9″)) is nothing then call 開啟隱藏表

end sub

在多個巨集中依次迴圈執行乙個(控制項按鈕**)

private sub commandbutton1_click()

static runmacro as integer

select case runmacro

case 0

巨集1runmacro = 1

case 1

巨集2runmacro = 2

case 2

巨集3runmacro = 0

end select

end sub

在兩個巨集中依次迴圈執行乙個並相應修改按鈕名稱(控制項按鈕**)

private sub commandbutton1_click()

with commandbutton1

if .caption = 「保護工作表」 then

call 保護工作表

caption = 「取消工作表保護」

exit sub

end if

if .caption = 「取消工作表保護」 then

call 取消工作表保護

caption = 「保護工作表」

exit sub

end if

end with

end sub

在三個巨集中依次迴圈執行乙個並相應修改按鈕名稱(控制項按鈕**)

option explicit

private sub commandbutton1_click()

with commandbutton1

if .caption = 「巨集1″ then

call 巨集1

caption = 「巨集2″

exit sub

end if

if .caption = 「巨集2″ then

call 巨集2

caption = 「巨集3″

exit sub

end if

if .caption = 「巨集3″ then

call 巨集3

caption = 「巨集1″

exit sub

end if

end with

end sub

根據a1單元文字隱藏/顯示按鈕(控制項按鈕**)

private sub worksheet_selectionchange(byval target as range)

if range(「a1″) > 2 then

= 1else

= 0end if

end sub

private sub commandbutton1_click()

重排視窗

end sub

當前單元返回按鈕名稱(控制項按鈕**)

private sub commandbutton1_click()

activecell =

end sub

當前單元內容返回到按鈕名稱(控制項按鈕**)

private sub commandbutton1_click()

= activecell

end sub

奇偶頁分別列印

sub 奇偶頁分別列印()

dim i%, ps%

ps = executeexcel4macro(「 『總頁數

msgbox 「現在列印奇數頁,按確定開始.」

for i = 1 to ps step 2

from:=i, to:=i

next i

msgbox 「現在列印偶數頁,按確定開始.」

for i = 2 to ps step 2

from:=i, to:=i

next i

end sub

自動列印多工作表第一頁

sub 自動列印多工作表第一頁()

dim sh as integer

dim x

dim y

dim sy

dim syz

x = inputbox(「請輸入起始工作表名字:」)

sy = inputbox(「請輸入結束工作表名字:」)

y = sheets(x).index

syz = sheets(sy).index

for sh = y to syz

sheets(sh).select

sheets(sh).printout from:=1, to:=1

next sh

end sub

查詢a列文字迴圈插入分頁符

sub 迴圈插入分頁符()

『 selection = workbooks(「臨時表」).sheets(「表2″).range(「a1″) 呼叫指定位址內容

dim i as long

dim times as long

times = 「分頁」)

『times代表迴圈次數,執行前把times賦值即可(不可小於1,不可大於2147483647)

for i = 1 to times

call 插入分頁符

next i

end sub

Excel常用技巧

一 規範高效的工作方式 1.複製工作表,右鍵單擊工作表標籤,移動或複製選單 2.插入或刪除多行 先插入或刪除一行,然後重複按f4鍵 f4鍵功能是重複上一次操作 定位您要插入的位置,向下選擇您要插入的行數,然後選擇插入行命令,或使用f4鍵 3.查詢工作表 右鍵單擊excel視窗左下角工作表表查詢前頭,...

EXCEL常用技巧

excel 2007 常用技巧整理 一 基本操作 1.excel初始化 左上角介面office 按鈕 excel選項,進行excel的初始化啟動引數設定,包括新工作薄的格式設定,最近檔案列表,使用者名稱和預設位置等 2.xlstart資料夾 excel選項 高階 啟動時自動開啟此目錄中的所有檔案 3...

excel常用函式

函式 1 mid函式 mid函式是excel中乙個強大的輔助函式,作用是從指定字串中指定位置提取指定個數字元。mid函式語法 mid text,start num,num chars text表示指定的字串,一般為引用的單元格 start num表示指定位置 num chars表示指定個數 例 在a...