title: How to Extract First Word of Cell and Copy into another Column
body: <p>I am having trouble extracting the first word of text and copying it into a new cell. This is what I have so far. Any help would be greatly appreciated.</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
  Dim i As Integer
  Dim str As String
  Dim lonstr As String
  
  i = 1
  
  For i = 1 To 500
  
  str = Worksheets("SR060-SR070(2)").Cells(i + 1, "D").Text
  longstr = GETFIRSTWORD(str)
  
  Worksheets("SR060-SR070(2)").Cells(i + 1, "U").Value = longstr
  
  Next i 'goes to next row
  
  End Sub
  
  
  Function GETFIRSTWORD(Text As String, Optional Separator As Variant)
  
  Dim firstword As String
  
  If IsMissing(Separator) Then
   Separator = " "
   End If
  
  
  firstword = Left(Text, InStr(1, Text, Separator, vbTextCompare))
  
  
  GETFIRSTWORD = Replace(firstword, Separator, "")
  
  End Function
  </code></pre>