Alex Campbell
asked on
How to write a custom Excel 2016 function that gets first two characters of cell if numbers?
If the cell's first three characters are 01-, I want them to be picked up.
If the cell is blank, I want the function to show 00-.
Example-of-Function-Desired.jpg
ASKER
Sorry, I forgot to include Custom with function in the question.
Then you can use this
For row 9: =CombineText(B9:D9)
Function CombineText(rg As Range) As String
Dim col As Integer
If rg.Columns.Count = 3 And rg.Rows.Count = 1 Then
For col = 1 To 3
If rg.Cells(1, col) = "" Then
CombineText = CombineText & "00"
Else
CombineText = CombineText & Left(rg.Cells(1, 1), 2)
End If
If col < 3 Then
CombineText = CombineText & "-"
End If
Next col
End If
End Function
For row 9: =CombineText(B9:D9)
ASKER
I tried out the function, but when the 2nd column changed, the function didn't update.
Level2NotUpdated.jpg
Level2NotUpdated.jpg
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Great, thanks!
=IF(ISBLANK(B9),"00-",LEFT