好的,所以我想做的就是创建一个函数来优化我对数据透视表数据进行细分的方式。这些数据有不同的形式,如“245896321 - 名称”,“名称”或“名称23123”,如果单元格包含特定文本(人姓),我希望它返回人名,但它只返回#VALUE!< / p>
提前致谢!你非常美!
我也很抱歉,如果你想让修改感觉自由,我的编码会伤害你的眼睛,只是在两天前开始冒险进入编码世界! :)
Function Financeiro (Line) as String
'=IF(ISNUMBER(SEARCH("*Person*", Line)), "Person Name")
If Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Ormelli*", Line)) Then
Financeiro = "Fernando Ormelli"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Fortuna*", Line)) Then
Financeiro = "Ricardo Fortuna"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Manocchio*", Line)) Then
Financeiro = "Ricardo Manocchio"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Stanquini*", Line)) Then
Financeiro = "Helder Stanquini"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Ivanete*", Line)) Then
Financeiro = "Ivanete Leite"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Freitas*", Line)) Then
Financeiro = "João Freitas"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Khan*", Line)) Then
Financeiro = "Marcelo Khan"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Filho*", Line)) Then
Financeiro = "Marco Filho"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Rocha*", Line)) Then
Financeiro = "Natalia Rocha"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Carvalho*", Line)) Then
Financeiro = "Vinicius Carvalho"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*SAE*", Line)) Then
Financeiro = "SAE"
ElseIf Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search("*Raphael*", Line)) Then
Financeiro = "Raphael Vieira"
Else
Financeiro = "Manual"
End If
End Function
答案 0 :(得分:1)
Application.WorksheetFunction.Search
将抛出运行时错误:尝试改为:
If Application.WorksheetFunction.IsNumber(Application.Search("*Ormelli*", Line)) Then
'...
省略WorksheetFunction
将行为从触发运行时错误切换为返回错误值。
或者只是使用:
If Line Like "*Ormelli*" Then
'...
我认为更容易理解。