Return text before a specific character

To return text before a specific character we can apply a combination of Excel LEFT and FIND functions

Example: Return text before a specific character

Return text before a specific character

METHOD 1. Return text before a specific character

EXCEL

=LEFT(B5,(FIND("/",B5,1)-1))
The formula returns all of the text before the / sign, which in this example will return Exceldome Solutions. You can change the / sign to any character that is captured in the cell from which you want to return the text.

METHOD 1. Return text before a specific character using VBA

VBA

Sub Return_text_before_a_specific_character()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'return text before the "/" sign
ws.Range("C5") = Left(ws.Range("B5"), (Application.WorksheetFunction.Find("/", ws.Range("B5"), 1) - 1))

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
Text: If using the exact VBA code the string from which you want to extract text needs to be captured in cell ("B5").

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Text: Select the cell that captures the string from which you want to extract text by changing the cell reference ("B5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Character: In this example we are returning all of the text before the "/" sing. You can change this in the VBA code to any character that is captured in the cell that captures the string from which you want to extract the text.

METHOD 2. Return text before a specific character using VBA with a formula function

VBA

Sub Return_text_before_a_specific_character()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'return text before the "/" sign
ws.Range("C5").Formula = "=LEFT(B5,(FIND(""/"",B5,1)-1))"

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
Text: If using the exact VBA code the string from which you want to extract text needs to be captured in cell ("B5").

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Text: Select the cell that captures the string from which you want to extract text by changing the cell reference ("B5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Character: In this example we are returning all of the text before the "/" sing. You can change this in the VBA code to any character that is captured in the cell that captures the string from which you want to extract the text.

Explanation about the formula used to return text before a specific character

EXPLANATION

EXPLANATION
To return text before a specific character we can apply a combination of Excel LEFT and FIND functions.
FORMULAS
=LEFT(string,(FIND("/",string,1)-1))

ARGUMENTS
string: The string that captures the text that you want to extract.