freonthewhite
New Member
- Joined
- Mar 21, 2025
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
Hi, I'm having trouble doing the VBA to create my own function. I have the excel formula to do it, but I just want to be able to have it be a function so that I can do something like =FirstWord(A2)
The excel formula that does this is:
=IF(ISERR(FIND(" ",A2)),A2, LEFT(A2, FIND(" ",A2)-1))
So I just want the function to feed the cell reference so that instead of using this formula I can just do =FirstWord(A2)
I tried the below, but it looks like I can't just do what I did.
Any help is appreciated, thank you
The excel formula that does this is:
=IF(ISERR(FIND(" ",A2)),A2, LEFT(A2, FIND(" ",A2)-1))
So I just want the function to feed the cell reference so that instead of using this formula I can just do =FirstWord(A2)
I tried the below, but it looks like I can't just do what I did.
Any help is appreciated, thank you
VBA Code:
Option Explicit
Function FirstWord(input_data)
input_data = IF(ISERR(FIND(" ",input_data)),input_data, LEFT(input_data, FIND(" ",input_data)-1))
FirstWord = input_data(word)
End Function