Related:
- Last word of phrase becomes first word
- Word apk for pc - Download - Word processors
- Number to text in word - Guide
- Word full screen - Guide
- Word watermark on all pages - Guide
- Backspace not working in word - Guide
5 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Oct 2, 2010 at 10:54 PM
Oct 2, 2010 at 10:54 PM
there are many ways to do it.. run this macro. the data will be like this with a heading in A1
heading
I need Help
I used a Macro
Please help me
the macro is
heading
I need Help
I used a Macro
Please help me
the macro is
Sub test() Dim j As Long, x As String, k As Long Dim r As Range, c As Range Columns("B:B").Delete Set r = Range(Range("A2"), Range("A2").End(xlDown)) For Each c In r j = Len(c) For k = j To 1 Step -1 'msgbox Mid(c, k, 1) If Mid(c, k, 1) = " " Then GoTo line1 Next k line1: x = Right(c, Len(c) - k) 'msgbox x x = x & " " & Mid(c, 1, k - 1) 'msgbox x Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = x Next c End Sub
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Oct 3, 2010 at 09:41 PM
Oct 3, 2010 at 09:41 PM
see whether this modified macro will work?
Sub test() Dim j As Long, x As String, k As Long Dim r As Range, c As Range Columns("B:B").Delete On Error GoTo line2 Set r = Range(Range("A2"), Range("A2").End(xlDown)) For Each c In r j = Len(c) For k = j To 1 Step -1 'msgbox Mid(c, k, 1) If Mid(c, k, 1) = " " Then GoTo line1 Next k line1: x = Right(c, Len(c) - k) 'msgbox x x = x & " " & Mid(c, 1, k - 1) 'msgbox x Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = x GoTo nextc line2: c.Offset(0, 1) = c nextc: Next c End Sub
I'm still getting the same error messege. Could this be because some of the cells that contain one word also contain hyphens? For example a cell contains the word ACP-CE and thats where the macro stops running and returns the error message - although, now all other one word cells ran with this modified macro.
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Oct 4, 2010 at 09:00 PM
Oct 4, 2010 at 09:00 PM
inadvertently you might have added a space at the end or some other mistake;. You CLEAR(NOT MERELY DELETE)-EDIT-CLEARALL of the one word cells.
however I am sending my sample file which you can download from the following web page
http://www.speedyshare.com/files/24550414/jeni_101004.xls
the macro is already in the vb editor of this file.you run the macro and see.
however I am sending my sample file which you can download from the following web page
http://www.speedyshare.com/files/24550414/jeni_101004.xls
the macro is already in the vb editor of this file.you run the macro and see.
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Oct 7, 2010 at 06:08 AM
Oct 7, 2010 at 06:08 AM
see whether this modified macro helps
Sub test() Dim j As Long, x As String, k As Long Dim r As Range, c As Range Columns("B:B").Delete On Error GoTo line2 Set r = Range(Range("A2"), Range("A2").End(xlDown)) For Each c In r If InStr(c, " ") = 0 Then GoTo line2 j = Len(c) For k = j To 1 Step -1 'MsgBox Mid(c, k, 1) If Mid(c, k, 1) = " " Then GoTo line1 Next k line1: x = Right(c, Len(c) - k) 'MsgBox x x = x & " " & Mid(c, 1, k - 1) 'MsgBox x c.Offset(0, 1) = x GoTo nextc line2: c.Offset(0, 1) = c nextc: Next c End Sub
Oct 3, 2010 at 01:22 PM
Thanks again!!