Tag: udf

EXCEL UDF DLL在excel adins中不可见

我跟着互联网上的教程如何创buildudf。 项目AutomationSample(类库)中名称为“AutomationSample”的类 using System.Runtime.InteropServices; using ExcelUdf.Automation; namespace AutomationSample { [ClassInterface(ClassInterfaceType.AutoDual)] [Guid("7CE422F9-BF1C-40B1-BD52-C9B31E09A2E2")] public class AutomationSample : UdfBase { public double AutomationSampleAdd(double a, double b) { return a + b; } public double AutomationSampleSubtract(double a, double b) { return a – b; } } } 类是COM可见的,编译后,我有DLL 之后,当我去excell – 添加插件selectExcel插件 – 去 – 自动化 我没有看到我的class上的名单。 我在这里错过了什么? 我也尝试手动注册与regasm的.dll,但即使没有看到它 即使从OP下载项目仍然无法使用C#.NET […]

防止Excel将UDFpath保存到公式单元格

我正在使用向Excel添加函数的自定义加载项,如UDF1(param1,param2)。 (1)示例调用单元格:= UDF1(param1,param2) 当保存实现UDF()的工作簿1时,Excel会悄悄地将加载项的path添加到UDF()的每个调用中。 这可以在卸载加载项和重新打开工作簿1时看到。 Excel要求更新外部引用,我点击“不要更新”。 (2)新的单元格内容:='\ … \ user \ Desktop \ Addin1'!UDF1(param1,param2) 如何在保存工作簿时防止Excel将path保存到加载项? 我希望新的单元格内容(2)匹配原始内容(1)。 (当不同的人使用分别安装在他们计算机的不同位置的相同的加载项时,这是特别讨厌的,因为每次工作簿是每个单元格时都要删除'\ ……!'path被另一个用户打开。) 编辑: 从Excel公式和http://www.jkp-ads.com/Articles/FixLinks2UDF.asp UDF中删除AddInpath是不是我所期待的,因为build议的“解决scheme”是变通办法。

VBA – 优化UDF(单元格颜色计数器)

我有一个主控制表和40-50个不同的数据表的工作簿,从外部来源(每个表格有30到500行和10到100列的数据)复制/粘贴到文件中。 该工作手册的目的是比较各种数据表栏中的单元格,如果符合某个方差标准,则将其突出显示; 然后每个数据表上的高亮显示的单元格被计数并显示在主控制表单上(使用UDF公式)。 在读完cpearson网站之后,我意识到,如果使用传统的条件格式,计算突出显示的单元格几乎是不可能的……但是我只有在我已经在VBA中将自定义的CF代码写入了40多张表格之后才明白这一点在数据表被使用复制/粘贴“刷新”之后,格式化可以被删除或者通过macrosbutton来应用)。 所以,经过一个很长的哭泣,我基本上重新创build条件格式(再次在VBA)使用循环来实现我的目标。 示例标准:比所比较的单元值小或大于25%。 示例数据表: [col 1] *** [col 2] 2014 *****2015 1 *********1.1 3 **********3 532 *******555 323 *******46 <<<this would Highlight 42 *******-112 <<<<this would highlight (The highlighting would occur if cells in col 2 are either 25% greater or less than the cells in col 1 cell for the corresponding […]

为什么不能存储我的数组?

我在vba中有这样的代码,试图填充从文本文件中提取的数据的dynamic数组,但出现一个错误 “下标超出范围”。 我曾尝试使这个非零基数组,但我收到相同的错误。 模块VBA option explicit Sub FromFileToExcel() Dim Delimiter As String Dim TextFile As Integer Dim validRow As Integer validRow = 0 Dim x As Integer Dim i As Integer Dim FilePath As String Dim FileContent As String Dim LineArray() As String Dim DataArray() As String FilePath = "C:\Users\Jlopez25\Desktop\bertha\INVPLANT.prn" TextFile = FreeFile Open FilePath […]

在函数中引用外部工作簿

我想有一个引用外部工作簿的function。 我写了这个代码,但我收到“运行时错误9”。 Function SiteStatus(Arg1 As String) As String Dim RFSTable As Workbook Dim RFSSheet As Worksheet Dim RFSSites As Range Set RFSTable = Workbooks("D:\RFS.xlsx") Set RFSSheet = RFSTable.Worksheets(3) Set RFSSites = RFSSheet.Range("B2:B10000") If WorksheetFunction.IsNA(WorksheetFunction.VLookup(Arg1, RFSSites, 1, 0)) = False Then SiteStatus = "ÎÇãæÔ" Else SiteStatus = "ÑæÔä" End If End Function

用户自定义函数返回#值

我遇到过这样的情况,需要我平均化一个Vlookups数组的结果。 我不知道如何用公式来实现这一点,似乎没有人在StackOverflow也没有任何想法。 所以我决定写一个函数来为我做这个工作。 不幸的是它返回“#VALUE!” 错误,我不知道为什么! 使用msgbox进行testing时,该函数可以正常工作。 我在下面注释了我的代码: Option Explicit Public Function AvgVlookup(Target_Array As String, Lookup_Array As String, Column_Index As Long) As Double Dim Result As Double Dim Total As Double Dim Counter As Long Dim TargetRange As Range Dim LookupRange As Range Dim Cell As Range ' Remove Absolute Indicator Target_Array = Replace(Target_Array, "$", "") […]

重新计算更改单元格背景

我有一个UDF结合IF语句将一个“X”与背景颜色的单元格,该公式不会重新计算当我改变背景颜色我怎么能使用Private Sub Workbook_SheetChange以便每次我改变一个单元格背景颜色所有公式重新计算。 公式很简单=IF(CELLCOLOR(M2)="Custom color or no fill","","x" 这是UDF Function CELLCOLOR(rCell As Range, Optional ColorName As Boolean) Application.Volatile Dim strColor As String Dim iIndexNum As Integer Select Case rCell.Interior.ColorIndex Case 1 strColor = "Black" iIndexNum = 1 Case 53 strColor = "Brown" iIndexNum = 53 Case 52 strColor = "Olive Green" iIndexNum = 52 Case […]

VBA UDFfunction导致excel“不响应”

我有一些非常简单的代码导致Excel崩溃。 我已经debugging了代码中可以看到的variables,它们看起来很好,除了几秒之后,Now()不会改变,waitTime也不会改变 – 虽然时间不同,即时间没有前移(例如,现在可能卡在3:00:05,waitTime卡在3:00:09)。 而application.wait不会等待我要求的5秒钟。 单元格的字体颜色也不会改变。 我不知道如何进一步debugging。 在工作表“sheet1”中,我有以下单元格条目 – 在C8中我有一个手动更改的数字。 在D8我有 =if(C8>25,"yup",startFlash(C8)) 这工作正常。 它调用没有问题的function。 这里是macros代码: Dim waitTime As Date, stopTime As Date Function startFlash(x As String) Beep stopTime = TimeSerial(Hour(Now()), Minute(Now()) + 2, Second(Now())) Call sflash MsgBox "done" End Function Sub sflash() Do While waitTime <= stopTime With Sheet1.Range("c8").Font If .ColorIndex = 3 Then .ColorIndex […]

当另一个工作簿处于活动状态时,UDF引用已命名的表错误

现在已经确定解决scheme了 我是一个build立UDF的VBA新手。 这个UDF包含许多在工作簿中的其他工作表上引用Excel表格的查找函数,比如: Twirecol = Application.WorksheetFunction.VLookup(i, Range("iterationtable"), 2, False) 麻烦的是,如果另一个工作簿处于活动状态,那么当Excel重新计算公式时,将返回一个#VALUE错误。 我看到很多关于如何引用VBA和UDF中的其他工作簿和工作表的解决scheme,但是我不知道如何适当地限制这些表对象,以便他们将注意力集中在UDF所在的工作簿上。 请注意,我正在寻找一个不依赖于工作表名称或工作簿文件名或path的解决scheme,因为所有这些都可能随时间而改变。 这是我的名字经理这个工作簿: 名称经理 这是整个UDF代码: Public Function voltagedrop(trenchlength As Integer, intlength As Integer) As String Application.Volatile Dim TLX As Integer Dim ILX As Integer Dim TVD As Single Dim IVD As Single Dim VD As Single Dim Twirecol As Integer Dim Iwirecol As Integer Dim […]

无法在UDF的单元格中写入string

Sub Makro() Dim a As String Dim b As String Cells(1, 1).Value = myfunction(X, X) If Range("A1") = "XX" Then MsgBox "True" Else MsgBox "False" End If End Sub Function myfunction(a, b) As String myfunction = a + b End Function “A1”单元格值等于0.它必须是XX。