Move first word to the end

This tutorial shows how to move the first word to the end of the string through the use of an Excel formula, with the RIGHT, LEN, FIND and LEFT functions, or VBA

EXCEL FORMULA 1. Move first word to the end using the RIGHT, LEN, FIND and LEFT functions

EXCEL

Hard coded formula
Move first word to the end
Cell reference formula
Move first word to the end
=RIGHT("bread butter milk",LEN("bread butter milk")-FIND(" ","bread butter milk"))&" "&LEFT("bread butter milk",FIND(" ","bread butter milk")-1)
=RIGHT(B5,LEN(B5)-FIND(" ",B5))&" "&LEFT(B5,FIND(" ",B5)-1)
GENERIC FORMULA

=RIGHT(string,LEN(string)-FIND(" ",string))&" "&LEFT(string,FIND(" ",string)-1)

ARGUMENTS
string: A string in which you want to move the first word to the end.

GENERIC FORMULA

=RIGHT(string,LEN(string)-FIND(" ",string))&" "&LEFT(string,FIND(" ",string)-1)

ARGUMENTS
string: A string in which you want to move the first word to the end.

EXPLANATION

This formula uses the RIGHT, LEN, FIND and LEFT functions to move the first word to the end of a string.
Click on either the Hard Coded or Cell Reference button to view the formula that either has the string in which you want to move the first word to the end entered directly in the formula or referenced to a cell.

In this example we are moving the word 'bread', which is the first word in cell B5, to the end of the cell.

VBA CODE 1. Move first word to the end using VBA

VBA

Hard coded against single cell
Sub Move_first_word_to_the_end()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'move the first word in a string to the end
ws.Range("C5") = Right("bread butter milk", Len("bread butter milk") - InStr("bread butter milk", " ")) & " " & Left("bread butter milk", InStr("bread butter milk", " ") - 1)

End Sub

Cell reference against single cell
Sub Move_first_word_to_the_end()
'declare variables
Dim ws As Worksheet
Dim rng As Range
Set ws = Worksheets("Analysis")
Set rng = ws.Range("B5")
'move the first word in a string to the end
ws.Range("C5") = Right(rng, Len(rng) - InStr(rng, " ")) & " " & Left(rng, InStr(rng, " ") - 1)

End Sub

Hard coded against range of cells
Sub Move_first_word_to_the_end()
'declare variables
Dim ws As Worksheet
Dim strString(4) As String
Set ws = Worksheets("Analysis")
strString(0) = "bread butter milk"
strString(1) = "milk butter bread apple"
strString(2) = "apple milk butter bread"
strString(3) = "butter apple milk"

'move the first word in a string to the end

For i = 0 To 3
strStringReturn = strString(i)
x = 5
x = x + i
ws.Range("C" & x) = Right(strStringReturn, Len(strStringReturn) - InStr(strStringReturn, " ")) & " " & Left(strStringReturn, InStr(strStringReturn, " ") - 1)
Next i

End Sub

Cell reference against range of cells
Sub Move_first_word_to_the_end()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")

'move the first word in a string to the end

For i = 5 To 8
ws.Range("C" & i) = Right(ws.Range("B" & i), Len(ws.Range("B" & i)) - InStr(ws.Range("B" & i), " ")) & " " & Left(ws.Range("B" & i), InStr(ws.Range("B" & i), " ") - 1)

Next i

End Sub

RELATED TOPICS

Related Topic Description Related Topic and Description
How to return the first word from a string through the use of an Excel formula or VBA

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel LEFT function returns the specified number of characters from a specified string, starting from the left side
The Excel RIGHT function returns the specified number of characters from a specified string, starting from the right side
The Excel LEN function returns the number of characters in a specified string
The Excel FIND function returns the position of a specific sub-string within a string