macro to split word

AC

Board Regular
Joined
Mar 21, 2002
Messages
153
I need a macro to split a word out of a cell and put each letter in a different cell, regardless of how long the word is, the trick is I need it to keep the first letter where it is and put the other letters up 2 rows and over 1 column, so if I put test in cell A50 the macro would leave t in A50 and put e in B48 s in C46 and t in D44. can this be done using excel 2003? Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Something like this should work, but with decreasing row location (or column) there will be problems with words of more than 25 characters.
Code:
Sub test()
    Dim startCell As Range
    Dim rIncriment As Long, cIncriment As Long
    Dim wordToSplit As String
    Dim i As Long
    Set startCell = Range("A50")
    rIncriment = -2: cIncriment = 1
    
    wordToSplit = CStr(startCell.Value)
    For i = 0 To Len(wordToSplit) - 1
        startCell.Offset(i * rIncriment, i * cIncriment).Value = Mid(wordToSplit, i + 1, 1)
    Next i
End Sub
 
Upvote 0
Deleted my post. I misread and didn't offset the columns in my code. :(
 
Last edited:
Upvote 0
AC,

The macro will split a word in the ActiveCell (A50), per you request.

Enter the word test in cell A50. Then run the macro.



Sample data before the macro:


Excel Workbook
ABCD
43
44
45
46
47
48
49
50test
Sheet1





After the macro:


Excel Workbook
ABCD
43
44t
45
46s
47
48e
49
50t
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub SplitWord()
' hiker95, 04/13/2011
' http://www.mrexcel.com/forum/showthread.php?t=543443
Dim H As String, a As Long
Dim r As Long, c As Long
H = ActiveCell.Value
r = ActiveCell.Row
c = ActiveCell.Column
ActiveCell.Value = Left(H, 1)
For a = 2 To Len(H) Step 1
  r = r - 2
  c = c + 1
  Cells(r, c) = Mid(H, a, 1)
Next a
End Sub


Then run the SplitWord macro.
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top