在Excel中引用其他宏
在excel的使用過程中,會用到一些自定義函數,可以使用宏輕松的實現這些功能,問題是必須使用“啟用宏的excel”,這樣用戶每次打開時都要啟用宏。
現用以按背景色計劃為例,解決以上問題:
1.新建一個空白的excel,按alt+F11,打開VB界面,點擊“插入”---“模塊”---錄入以下代碼:
//這個方法是計算相同顏色的單元格個數
Function CountColor(col As Range, countrange As Range) As Integer
Dim icell As Range
Application.Volatile
For Each icell In countrange
If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
CountColor = CountColor + 1
End If
Next icell
End Function
//這個方法是計算相同顏色的單元格中的數據之和
Function SumColor(col As Range, sumrange As Range) As Integer
Dim icell As Range
Application.Volatile
For Each icell In sumrange
If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
SumColor = Application.Sum(icell) + SumColor
End If
Next icell
End Function
在VB中點擊保存,保存excel時選擇“另存為”--“Excel 加載宏(*.xlam)”,把這個excel存儲為sum.xlam文件。
2.打開要計算的excel,在此中選擇開發工具--加載宏--瀏覽--選擇sum.xlam,選中,點確認。
3.完成。
4.這樣操作以后,只要打開excel就可以使用sumColor這個函數,不用啟用宏。
總結
以上是生活随笔為你收集整理的在Excel中引用其他宏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机分级时无法度量视频播放,Win7
- 下一篇: 中国AIGC产业峰会举行 微软百度等十余