vba help - Split data seperator Black Star

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
983
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

How to split the data, and Seperate name from Black Star.

Column A input data and Expected output is in Column B and c.

Book7
ABC
1NameExpected OutputCount with special character
2Sachin★★★Sachin3
3Dhoni★★Dhoni2
4Virat Kohli★Virat Kohli1
Sheet2



Thanks
mg
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Excel Formula:
B2=LEFT(A2,FIND("★",A2)-1)
C2==LEN(A2)-FIND("★",A2)+1
Or
Excel Formula:
B2=LEFT(A2,FIND("★",A2)-1)
C2=len(A2)-LEN(B2)
 
Last edited:
Upvote 0
Hi Mohadin,

Thanks for your help ,formula worked. But through vba I am not getting output.

.FormulaR1C1 = "=LEFT(RC[-1],FIND(""?"",RC[-1])-1)" this is recorded code.


★ star is getting replaced with ? in vba.



Thanks
mg
 
Upvote 0
Try

VBA Code:
Sub CountStars()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long
  
  a = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 2)
  For i = 1 To UBound(a)
    For j = 1 To Len(a(i, 1))
      If Mid(a(i, 1), j, 1) Like "[!A-Za-z ]" Then
        b(i, 1) = Left(a(i, 1), j - 1)
        b(i, 2) = Len(a(i, 1)) - j + 1
        Exit For
      End If
    Next j
  Next i
  Range("B2:C2").Resize(UBound(b)).Value = b
End Sub
 
Upvote 0
Hi Peter,

Very nice , liked your code, it worked. thanks ? (y)


Thanks
mg
 
Upvote 0
Hi Peter,

Can you add comment for this regual Experession :=====> If Mid(a(i, 1), j, 1) Like "[!A-Za-z ]" Then , what it means

While debugging the code, if it found special charecter it went inside the if condition.




Thanks
mg
 
Upvote 0
Hi Peter,

Very nice , liked your code, it worked. thanks ? (y)


Thanks
mg
You're welcome.


Can you add comment for this regual Experession :=====> If Mid(a(i, 1), j, 1) Like "[!A-Za-z ]" Then , what it means
It isn't a regular expression as such - just the use of the 'Like' operator. The ! means any character not in the list that follows it.
Therefore that line of code finds the first character in the cell that is not a letter (upper or lower case) or a space & uses that position to both extract the text before that position and to count the remaining characters starting from that position.

To be robust the list probably needs some more characters added in case you have hyphenated names (eg Harris-Jones) or names with apostrophes (eg O'Connor)
[!A-Za-z '-]

While debugging the code, if it found special charecter it went inside the if condition.
If that is a further question them I'm not sure what you mean.
 
Upvote 0
Hi Peter,

Thanks for your help learned something new here, Got it. ? (y)


Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,223,999
Messages
6,175,882
Members
452,679
Latest member
darryl47nopra

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