zoukankan      html  css  js  c++  java
  • 在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这个函数,不用启用宏。

  • 相关阅读:
    leetcode 33. Search in Rotated Sorted Array
    leetcode 28. Implement strStr()
    Scala函数
    布隆过滤器相关知识
    Storm 流式计算框架
    java高并发核心类 AQS(Abstract Queued Synchronizer)抽象队列同步器
    操作系统类型&操作系统结构&现代操作系统基本特征
    Kafka笔记
    Redis shell
    Lucene笔记
  • 原文地址:https://www.cnblogs.com/flyrain/p/excel_vb.html
Copyright © 2011-2022 走看看