在Excel中创建新功能 [英] Create new Function in Excel

查看:71
本文介绍了在Excel中创建新功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel中创建了一个" IF公式",并希望将其转换为我阅读多篇文章的函数;但无法将公式转换为函数:公式如下:

I created a "IF Formula" in excel and wanted to convert that formula in function I read multiple article; but unable to convert formula into function: Formula is as follows:

 =IF(LEFT(L3,4)=0321," 12 - ABC type",
 IF(LEFT(L3,3)=021," 543 - XYZ type",
 IF(ISERROR(SEARCH("T56_",L3))=FALSE,MID(L3,SEARCH("T56_",L3),19),
 IF(ISERROR(SEARCH("MCW",L3))=FALSE,MID(L3,SEARCH("MCW_",L3),10),
 "Logic Missing"))))

我只添加了公式中的4个 IF ;但实际公式中我有10种以上的IF逻辑.有没有一种方法可以在Function中创建此IF公式.

I just include the 4 IF's from the formula; but I have way more than 10 IF logic in the actual formula. Is there a way to create this IF formula in Function.

我已经尝试了下面提到的代码,但是它给了我#VALUE!错误.

I already tried the below mentioned code but it gave me #VALUE! error.

Function AccountType(dCell As Variant) As Long
If dCell = Left(dCell, 4) = "0321" Then
 AccountType = "12 - ABC type
ElseIf dCell = Left(dCell, 3) = "021" Then
 AccountType = "543 - XYZ type"
Else
 AccountType = "Logic Missing"
        End If
End Function

推荐答案

按照注释中的说明删除dcell =,并使函数返回String而不是Long.并且您在第三行中缺少".

As the comments stated remove the dcell = and make the function return a String instead of a Long. and you were missing a " in the third line.

Function AccountType(dCell As Variant) As String
    If Left(dCell, 4) = "0321" Then
        AccountType = "12 - ABC type"
    ElseIf Left(dCell, 3) = "021" Then
        AccountType = "543 - XYZ type"
    Else
        AccountType = "Logic Missing"
    End If
End Function

这篇关于在Excel中创建新功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆