Separating first and last names - vba

lordriel

Board Regular
Joined
Nov 1, 2005
Messages
68
Office Version
  1. 365
Platform
  1. Windows
I've seen several methods for separating names, or text, from one cell to two or more. However, none of them give a vba answer.

How would I code it, were it to be done when hitting a command button?
 
Anyway this is what I did... The first line works and the second line does not.
Rich (BB code):
 Sheets("Cpl-Child Info").Range("BP1").Value = "First Name"
  Sheets("Cpl-Child Info").Range("B2", Range("B" & Rows.Count).End(xlUp)).TextToColumns Destination:=Range("BP2"), DataType:=xlDelimited, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 9), Array(3, 9))
You noted that you had qualified the range with the sheet, but you only did it for the two blue ranges. You would need to add qualifications for the two red ones as well.
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Here is another macro that should work...
VBA Code:
Sub FirstNames()
  With Sheets("Cpl-Child Info").Range("B2", Sheets("Cpl-Child Info").Cells(Rows.Count, "B").End(xlUp))
    .Offset(-1, 66)(1).Value = "First Name"
    .Offset(, 66) = Evaluate(Replace(Replace("IF(#!@="""","""",LEFT(#!@,FIND("" "",#!@&"" "")-1))", "@", .Address), "#", "'Cpl-Child Info'"))
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,399
Messages
6,184,757
Members
453,254
Latest member
topeb

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