To flip words in an Excel cell (e.g., changing "John Doe" to "Doe John"), you must use a combination of text functions or a custom VBA script, as Excel does not have a single "Flip Words" button. For most users, the fastest method is using the TEXTSPLIT and TEXTJOIN functions in modern Excel versions, or a custom formula for older versions, to isolate the words and reorder them.
What You'll Need
- A computer with Microsoft Excel installed (Office 365, Excel 2021, or older versions).
- A dataset containing the text strings you wish to reverse.
- Basic familiarity with entering formulas into a cell.
Step-by-Step
Depending on your version of Excel, the method for flipping words differs. We will cover the modern dynamic array method first, followed by the traditional formula method and the VBA automation method.
Method 1: Using TEXTSPLIT and TEXTJOIN (Excel 365/2021)
This is the most efficient way to reverse words in a cell if you have a current version of Excel. These functions allow you to break a sentence into a list and then put it back together in reverse order.
- Identify the cell containing the text you want to flip (e.g., Cell A2 contains "Red Blue Green").
- Click on an empty cell where you want the flipped result to appear (e.g., B2).
- Enter the following formula:
=TEXTJOIN(" ", TRUE, SORTBY(TEXTSPLIT(A2, " "), SEQUENCE(1, COUNTA(TEXTSPLIT(A2, " ")), 1, -1))). - Press Enter. The formula works by splitting the text at every space, creating a sequence of numbers in descending order to tell Excel to sort the words backward, and then joining them back together with spaces.
- Hover your mouse over the bottom-right corner of cell B2 until the cursor becomes a small black cross (the fill handle).
- Click and drag the fill handle down to apply the formula to all other rows in your column.
Method 2: Using a Formula for Two-Word Strings (All Excel Versions)
If you only need to flip two words (like First Name and Last Name) and are using an older version of Excel, you can use a combination of FIND, LEFT, RIGHT, and MID functions.
- Assume your text "John Doe" is in cell A2.
- In cell B2, enter the following formula to extract the second word:
=MID(A2, FIND(" ", A2) + 1, LEN(A2)). - In cell C2, enter the following formula to extract the first word:
=LEFT(A2, FIND(" ", A2) - 1). - In cell D2, combine them with a space:
=B2 & " " & C2. - To clean up your sheet, you can copy the results in column D and use Paste Special > Values to remove the formulas and keep only the flipped text.
Method 3: Using VBA for Complex or Bulk Flipping
If you have thousands of cells with varying numbers of words, a User Defined Function (UDF) is the most powerful tool. This creates a new function called =FlipWords() that you can use anywhere in your workbook.
- Open your Excel workbook.
- Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
- In the top menu, go to Insert > Module. This opens a blank white window.
- Copy and paste the following code into the module window:
Function FlipWords(txt As String) As String Dim words() As String Dim i As Long Dim result As String words = Split(txt, " ") For i = UBound(words) To LBound(words) Step -1 result = result & words(i) & " " Next i FlipWords = Trim(result) End Function - Close the VBA window by clicking the X in the top right corner to return to your spreadsheet.
- In your sheet, click on an empty cell and type:
=FlipWords(A2)(assuming A2 is the cell you want to flip). - Press Enter and drag the formula down as needed.
- Crucial: You must save your file as an Excel Macro-Enabled Workbook (.xlsm), otherwise the VBA code will be deleted when you close the file.
Common Mistakes
- Ignoring Extra Spaces: If a cell has a trailing space (e.g., "John Doe "), the formula may treat that space as a word, resulting in a leading space in your flipped result. Use the
TRIM()function around your cell reference (e.g.,=FlipWords(TRIM(A2))) to prevent this. - Wrong File Format: Using the VBA method but saving the file as a standard .xlsx file. This removes the script, and your formulas will return a #NAME? error the next time you open the file.
- Overlooking Delimiters: Using a space " " as a delimiter when the data is actually separated by commas or tabs. Ensure the character inside the quotes in your formula matches the actual separator in your data.
- Circular References: Trying to enter the formula into the same cell that contains the original text. Formulas must always point to a different cell to avoid a circular reference error.
Tips
- Convert to Values: Once you have flipped your words, the cells are still dependent on formulas. To make the data permanent, select the flipped cells, press Ctrl + C, right-click on the same cells, and select Paste Values (the icon with "123").
- Handling Commas: If your data is in "Last, First" format, replace the space " " in the formulas with a comma and space ", " to ensure the punctuation is handled correctly.
- Flash Fill: For very simple patterns, try typing the flipped version of the first two rows manually in the adjacent column. Then, press Ctrl + E. Excel's Flash Fill may recognize the pattern and flip the rest of the column automatically without any formulas.
- Case Sensitivity: Remember that flipping words does not change the capitalization. If you need the new first word to be capitalized and the new last word to be lowercase, you will need to wrap your formula in
PROPER()orUPPER().
Troubleshooting
If your results are not appearing as expected, check these common failure points in order:
- #NAME? Error: This usually happens if you are using a function your version of Excel doesn't support (like TEXTSPLIT in Excel 2016) or if you haven't properly installed the VBA module. Check your Excel version or re-insert the VBA code.
- #VALUE! Error: This often occurs when the formula expects a space to separate words, but the cell is empty or contains only a single word. Ensure your data is consistent.
- Words are flipped but punctuation is misplaced: If you have a period at the end of a sentence, the period will stay attached to the last word, which then becomes the first word. To fix this, you would need a more complex VBA script that strips punctuation before flipping and re-adds it after.
- VBA Macro Blocked: If the VBA function doesn't work, look for a yellow "Security Warning" bar at the top of the spreadsheet that says "Macros have been disabled." Click Enable Content to allow the script to run.
Frequently Asked Questions
Can I flip the letters within a word instead of the words themselves?
Flipping letters (e.g., "Apple" to "elppA") requires a different approach. You cannot do this with standard formulas easily. You must use a VBA script that loops through every character in the string from the last index to the first index.
Does this work for cells with 10 or more words?
Yes, the TEXTSPLIT/TEXTJOIN method and the VBA method are dynamic and will work regardless of how many words are in the cell. The manual MID/LEFT formula method only works for two words.
Will this change the formatting of my cells?
No, formulas only affect the value displayed in the cell. Bold, italic, or cell color settings will remain unchanged, although the new cell containing the formula will have the default formatting of that column.
Is there a way to do this without formulas?
Yes, you can use the "Text to Columns" feature under the Data tab to split words into separate columns, then manually move the columns into the desired order, and finally use the CONCATENATE function or an ampersand (&) to join them back together.
Can I flip words across multiple cells at once?
You cannot flip words across multiple cells into one cell using a simple formula. You would first need to join the cells using TEXTJOIN and then apply the flipping logic to that combined string.