Remove characters from right
To remove characters from the right of the selected string you need to apply a combination of Excel LEFT and LEN functions
Example: Remove characters from right
SubRemove_characters_from_right()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'apply the formula to remove four characters from the right
ws.Range("D5") = Left(ws.Range("B5"), Len(ws.Range("B5")) - ws.Range("C5"))
ws.Range("D5") = Left(ws.Range("B5"), Len(ws.Range("B5")) - ws.Range("C5"))
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.
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 Analyst.
String: Ensure that the string from which you want to remove characters is captured in cell ("B5").
Number of Characters to Remove: Ensure that the number of characters that you want to remove from the selected string is captured in cell ("C5").
Worksheet Name: Have a worksheet named Analyst.
String: Ensure that the string from which you want to remove characters is captured in cell ("B5").
Number of Characters to Remove: Ensure that the number of characters that you want to remove from the selected string is captured in cell ("C5").
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code to any cell in a worksheet, that doesn't conflict with the formula.
String: Select the string from which you want to remove characters by changing cell reference ("B5") to any cell in the worksheet, that contains the string and doesn't conflict with the formula.
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code to any cell in a worksheet, that doesn't conflict with the formula.
String: Select the string from which you want to remove characters by changing cell reference ("B5") to any cell in the worksheet, that contains the string and doesn't conflict with the formula.
EXPLANATION
To remove characters from the right of the selected string you need to apply a combination of Excel LEFT and LEN functions.
To remove characters from the right of the selected string you need to apply a combination of Excel LEFT and LEN functions.
FORMULA
=LEFT(string,LEN(string)-num_char)
=LEFT(string,LEN(string)-num_char)
ARGUMENTS
string: The string from which you want to remove the selected number of characters.
num_char: The number of characters that you want to remove from the selected string.