Extracting Letters

kenpcli

Board Regular
Joined
Oct 24, 2017
Messages
129
How do I extract a letter from a group of numbers and put in into a different cell. For example: Cell B6 has A123456 and I want the letter A taken and put into cell A6 and leave the rest of the number in B, if B doesnt have a letter in it, then leave the A cell blank and color it yellow.

Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
This is what I have, but it says "expected end of statement" when it gets to the "A"

Range("A6").Formula = "=IF(LEFT(B6,1)="A","A",IF(LEFT(B6,1)="b","B", ""))"
 
Upvote 0
How about
Code:
   If Not IsNumeric(Left(Range("B6"), 1)) Then
      Range("A6") = Left(Range("B6"), 1)
      Range("B6") = Mid(Range("B6"), 2)
   Else
      Range("A6").Interior.Color = vbYellow
   End If
 
Upvote 0
Here is an alternate that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]  If Range("B6") Like "#*" Then
    Range("A6").Interior.Color = vbYellow
  Else
    Range("A6:B6") = Split(Application.Replace(Range("B6"), 2, 0, " "))
  End If[/td]
[/tr]
[/table]
 
Upvote 0
Like this
Code:
   Dim Cl As Range
   For Each Cl In Range("B6", Range("B" & Rows.Count).End(xlUp))
      If Not IsNumeric(Left(Cl, 1)) Then
         Cl.Offset(, -1) = Left(Cl, 1)
         Cl = Mid(Cl, 2)
      Else
         Cl.Offset(, -1).Interior.Color = vbYellow
      End If
   Next Cl
 
Upvote 0
I am trying to fit it between these two lines of code, but it doesnt work.
Code:
[COLOR=#ff0000] End With[/COLOR]
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
   Dim Cl As Range
   For Each Cl In Range("B6", Range("B" & Rows.Count).End(xlUp))
      If Not IsNumeric(Left(Cl, 1)) Then
         Cl.Offset(, -1) = Left(Cl, 1)
         Cl = Mid(Cl, 2)
      Else
         Cl.Offset(, -1).Interior.Color = vbYellow
      End If
   Next Cl
   
[COLOR=#ff0000]    Range("D515").Select[/COLOR]
 
Last edited by a moderator:
Upvote 0
In what way "Doesn't it work"?
Also when posting code, please use code tags, the # icon in the reply window
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,614
Members
452,661
Latest member
Nonhle

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