I have a VBA conditional function I hacked together (I'm a noob) that checks for a name in a cell and then returns appropriate variations if one of the conditions is true, otherwise it returns a blank "". Instead of returning a blank, I'd like it to return the default cell value.
As an example, I have the following cells and results based on my function:
Cells
A B
1 Bob Bob Rob Robert
2 Mike Mike Michael
3 Dan Dan Daniel
4 Scott
I'd like the result for B4 to return the default value in A4 (Scott), rather then a blank, like this:
Cells
A B
1 Bob Bob Rob Robert
2 Mike Mike Michael
3 Dan Dan Daniel
4 Scott Scott
Any help would be appreciated:
Here's my function (abbreviated version without all names included in ElseIf):
Function NameList(pVal As String) As String
If pVal = "Bob" Then
NameList = "Bob Rob Robert"
ElseIf pVal = "Mike" Then
NameList = "Mike Michael"
ElseIf pVal = "Dan" Then
NameList = "Dan Daniel"
Else
NameList = ""
End If
End Function
Thanks!
I thinkElse
NameList = pVal
solves your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With