excel自定义函数源代码
求哪位高手给我解释一下一下这一段代码,是什么意思,就是怎么去读懂它'显示一级科目FUNCTIONFunctionKM(be_searched)FOUND=FalseIfT...
求哪位高手给我解释一下一下这一段代码,是什么意思,就是怎么去读懂它
'显示一级科目 FUNCTION
Function KM(be_searched)
FOUND = False
If Trim(be_searched) = "" Then
KM = "*"
Exit Function
End If
For X = 5 To 300
If Left(be_searched, 4) = Sheets("目录").Cells(X, 3) Then
FOUND = True
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
KM = Sheets("目录").Cells(X, 4)
Else
KM = "代码错"
End If
End Function
'显视二级科目 FUNCTION
Function KM2(TO_BE_SEARCHED As String)
If TO_BE_SEARCHED = "" Then
KM2 = "*"
Exit Function
End If
FOUND = False
For X = 4 To 500
If TO_BE_SEARCHED = Sheets("目录").Cells(X, 3) Then
FOUND = True
FONT_COLOR = Sheets("目录").Cells(X, 4).Font.ColorIndex
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
End Function 展开
'显示一级科目 FUNCTION
Function KM(be_searched)
FOUND = False
If Trim(be_searched) = "" Then
KM = "*"
Exit Function
End If
For X = 5 To 300
If Left(be_searched, 4) = Sheets("目录").Cells(X, 3) Then
FOUND = True
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
KM = Sheets("目录").Cells(X, 4)
Else
KM = "代码错"
End If
End Function
'显视二级科目 FUNCTION
Function KM2(TO_BE_SEARCHED As String)
If TO_BE_SEARCHED = "" Then
KM2 = "*"
Exit Function
End If
FOUND = False
For X = 4 To 500
If TO_BE_SEARCHED = Sheets("目录").Cells(X, 3) Then
FOUND = True
FONT_COLOR = Sheets("目录").Cells(X, 4).Font.ColorIndex
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
End Function 展开
展开全部
'显示一级科目 FUNCTION
Function KM(be_searched)
FOUND = False '初始变量为否
If Trim(be_searched) = "" Then '如果参数为空,则显示“*”,并退出函数
KM = "*"
Exit Function
End If
For X = 5 To 300 '遍历"目录"工作簿中(5,3)~(300,3)区域
If Left(be_searched, 4) = Sheets("目录").Cells(X, 3) Then '如果参数前4个字符与遍历区域中字符相同,则设置变量为真,并退出循环,(X,3)为相同字符单元格
FOUND = True
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
KM = Sheets("目录").Cells(X, 4) '如果FOUND为真,则显示KM为相同单元格的下一单元格内容,否则显示"代码错"
Else
KM = "代码错"
End If
End Function
'显视二级科目 FUNCTION
Function KM2(TO_BE_SEARCHED As String)
If TO_BE_SEARCHED = "" Then '如果参数为空,则显示“*”,并退出函数
KM2 = "*"
Exit Function
End If
FOUND = False '初始变量为否
For X = 4 To 500 '遍历"目录"工作簿中(4,3)~(500,3)区域
If TO_BE_SEARCHED = Sheets("目录").Cells(X, 3) Then '如果参数与遍历区域中字符相同,则设置变量为真,并退出循环,(X,3)为相同字符单元格
FOUND = True
FONT_COLOR = Sheets("目录").Cells(X, 4).Font.ColorIndex '设置字体颜色与相同单元格的下一单元格相同
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
End Function
Function KM(be_searched)
FOUND = False '初始变量为否
If Trim(be_searched) = "" Then '如果参数为空,则显示“*”,并退出函数
KM = "*"
Exit Function
End If
For X = 5 To 300 '遍历"目录"工作簿中(5,3)~(300,3)区域
If Left(be_searched, 4) = Sheets("目录").Cells(X, 3) Then '如果参数前4个字符与遍历区域中字符相同,则设置变量为真,并退出循环,(X,3)为相同字符单元格
FOUND = True
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
KM = Sheets("目录").Cells(X, 4) '如果FOUND为真,则显示KM为相同单元格的下一单元格内容,否则显示"代码错"
Else
KM = "代码错"
End If
End Function
'显视二级科目 FUNCTION
Function KM2(TO_BE_SEARCHED As String)
If TO_BE_SEARCHED = "" Then '如果参数为空,则显示“*”,并退出函数
KM2 = "*"
Exit Function
End If
FOUND = False '初始变量为否
For X = 4 To 500 '遍历"目录"工作簿中(4,3)~(500,3)区域
If TO_BE_SEARCHED = Sheets("目录").Cells(X, 3) Then '如果参数与遍历区域中字符相同,则设置变量为真,并退出循环,(X,3)为相同字符单元格
FOUND = True
FONT_COLOR = Sheets("目录").Cells(X, 4).Font.ColorIndex '设置字体颜色与相同单元格的下一单元格相同
Exit For 'STOP SEARCHING
End If
Next X
If FOUND Then
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询