Separating letters from the end into another cell

Gautham A

Board Regular
Joined
May 25, 2020
Messages
107
Office Version
  1. 2016
Platform
  1. Windows
Hello
In the cell A1,it has the value abcdefghSuccess
I want to separate the last 7 letters into a another cell such that A1 will be abcdefgh and B1 will be Success.
How to do this in VBA? Thanks in advance
 
Hi Rick
I tried this one as well,still there is no change in the output.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Then you are going to have to post your workbook on a free file sharing site (I would strongly recommend DropBox as it is a proven safe website) so that we can see exactly what your data looks like.
 
Upvote 0
Hi Rick,

I'm not sure how to upload in Dropbox. Let me know the steps please
 
Upvote 0
Here is another macro for you to consider

VBA Code:
Sub test5()
  Dim c As Range, i As Long, j As Long, lr As Long
  '
  lr = Range("A" & Rows.Count).End(3).Row
  ReDim a(1 To lr, 1 To 2)
  For Each c In Range("A1:A" & lr)
    i = i + 1
    a(i, 1) = c
    j = InStrRev(c, "Success", , vbTextCompare)
    If j = 0 Then j = InStrRev(c, "Running", , vbTextCompare)
    If j > 0 Then
      a(i, 1) = Left(c, j - 1)
      a(i, 2) = Mid(c, j, 7)
    End If
  Next c
  Range("A1").Resize(UBound(a), 2).Value = a
End Sub
 
Upvote 0
Hi Dante,

This works. This separates the last 7 letters into the next cell. Thank you so much.
One final question, What if I have "Starting" instead of "Running".
 
Upvote 0
One final question, What if I have "Starting" instead of "Running".
give me a moment

Ok. Try this

VBA Code:
Sub test6()
  Dim a As Variant, i As Long, j As Long, n As Long
  '
  a = Range("A1:B" & Range("A" & Rows.Count).End(3).Row).Value2
  For i = 1 To UBound(a, 1)
    j = InStrRev(a(i, 1), "Success", , vbTextCompare)
    If j > 0 Then
      n = 7
    Else
      j = InStrRev(a(i, 1), "Starting", , vbTextCompare)
      If j > 0 Then n = 8
    End If
    If j > 0 Then
      a(i, 2) = Mid(a(i, 1), j, n)
      a(i, 1) = Left(a(i, 1), j - 1)
    End If
  Next i
  Range("A1").Resize(UBound(a), 2).Value = a
End Sub
 
Upvote 0
This code works like a gem. Thank you so much Dante. Was struggling for a week to get rid of this. Also appreciate Rick for his efforts.
 
Upvote 0
I was so locked into the method I chose to attack your problem with that it never occurred to me to step back and try a different approach. Kudos to Dante for doing so.
 
Upvote 0
What about one more attempt at splitting the whole column at once with text to columns?
I've assumed that Success, Running or whatever the words are will occur at most once in a cell.

VBA Code:
Sub Split_Data()
  Dim SplitItem As Variant

  For Each SplitItem In Split("Success|Running", "|")   '<- Add/change words if required
    Columns("A").Replace What:=SplitItem, Replacement:="|" & SplitItem, LookAt:=xlPart, MatchCase:=False
  Next SplitItem
  Columns("A").TextToColumns DataType:=xlDelimited, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:="|"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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