Examine text string and abbreviate it

Burrgogi

Active Member
Joined
Nov 3, 2005
Messages
335
Office Version
  1. 2010
Platform
  1. Windows
Hello, I have the following text in column D:

96% with 3335 reviews (Overwhelmingly Positive)
95% with 971 reviews (Overwhelmingly Positive)
84% with 6341 reviews (Very Positive)
88% with 4622 reviews (Very Positive)
73% with 157 reviews (Mostly Positive)
80% with 64 reviews (Positive)

Is there a macro that can examine the words in parenthesis and abbreviated in a separate column? for example: Take "Very Positive" from the text string and have it displayed as "VP" in a separate column.
(Just taking the first letter of each word). The only exception would be when the review is just "(Positive)" only -- see the very last line in the sample I provided above. In such a case, I would like to have it abbreviated as "Pos". If that latter part is too difficult, I'm happy to just settle for just the first letter of each word; OP, VP, MP.

I would like column C to contain the final result. Like so:
OP
OP
VP
VP
MP
Pos
 
Last edited:
You are most welcome!
Glad I was able to help. It was a fun little challenge!
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If you need vba scrip to paste into existing code:
VBA Code:
Option Explicit
Sub test()
Dim cell As Range, s
Range("C1:C10000").ClearContents
For Each cell In Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    s = Split(cell.Value, "(")
    s = s(UBound(s))
    s = Split(s)
    With cell.Offset(0, -1)
        If UBound(s) = 0 Then
            .Value = Left(s(0), 3)
        Else
            .Value = UCase(Left(s(0), 1) & Left(s(1), 1))
        End If
     End With
Next
End Sub
This also works for text string with even multiple () inside
Book1
CD
1OPaaa () --- 96% with 3335 reviews (Overwhelmingly Positive)
2OP95% with 971 reviews (Overwhelmingly Positive)
3VP84% with 6341 reviews (Very Positive)
4VP88% with 4622 reviews (Very Positive)
5MP73% with 157 reviews (Mostly Positive)
6Pos80% with 64 reviews (Positive)
7Mix80% with 64 reviews (Mix)
Sheet2
 
Upvote 0
If you need vba scrip to paste into existing code:
VBA Code:
Option Explicit
Sub test()
Dim cell As Range, s
Range("C1:C10000").ClearContents
For Each cell In Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    s = Split(cell.Value, "(")
    s = s(UBound(s))
    s = Split(s)
    With cell.Offset(0, -1)
        If UBound(s) = 0 Then
            .Value = Left(s(0), 3)
        Else
            .Value = UCase(Left(s(0), 1) & Left(s(1), 1))
        End If
     End With
Next
End Sub
This also works for text string with even multiple () inside
Book1
CD
1OPaaa () --- 96% with 3335 reviews (Overwhelmingly Positive)
2OP95% with 971 reviews (Overwhelmingly Positive)
3VP84% with 6341 reviews (Very Positive)
4VP88% with 4622 reviews (Very Positive)
5MP73% with 157 reviews (Mostly Positive)
6Pos80% with 64 reviews (Positive)
7Mix80% with 64 reviews (Mix)
Sheet2

Very nice, thank you! @bebo021999 Now I have 2 effective versions. Man, you guys are so good at this stuff, it's amazing. I wish I was an VBA expert.
 
Upvote 0

Forum statistics

Threads
1,213,492
Messages
6,113,967
Members
448,537
Latest member
Et_Cetera

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