I have data in cells A1:A1000. It is a list of names followed by a small note, like this:
Easy! I don't know what version of Excel you are using, but in short you want to do a Convert Text to Columns
and then split the cells using a delimiter of "
. This will leave you with two columns, one of the data you want and one you can just delete.
Here is the walk through in Office 2010:
Data
menuConvert Text to Columns
menuDelimited
and hit next
Other
box, type "
Finish
Done! Now you have all your names in column A and you can just delete column B.
To sum up, do a "Convert Text to Columns" and then split the cells using a delimiter of "
. Super easy and fast.
few options:
Replace
Range("A1:A1000").Replace """*", vbNullString
If you require to manipulate the value further then the below are more appropriate:
With Regex:
Dim str As String, strClean As String
Dim cell As Range
For Each cell In Range("A1:A1000")
With CreateObject("vbscript.regexp")
.Pattern = "\""(.*)"
.Global = True
cell = .Replace(cell, vbNullString)
End With
Next cell
Without Regex, splitting the string:
Dim strSplit() As String
Dim cell As Range
For Each cell In Range("A1:A1000")
If (cell.Value <> vbNullString) Then
cell.Value = Split(cell.Value, """")(0)
End If
Next cell
Sub Macro1()
For Row = 1 To 1000
S = Range("A" & Row).Cells.Value
Pos = InStr(S, Chr(34))
If Pos > 0 Then Range("A" & Row).Cells.Value = Left(S, Pos - 1)
Next
End Sub
Here is a nifty trick without macros:
Select the proper range (or even just click on A
to select the entire column) and then do Ctrl+F
, click Replace
, in Find
write exactly "*
and leave the Replace with
box empty. Now click Replace all
and tada !
It replaces everything after (and including) the quote with nothing because it uses *
as a wildcard you left the replace box empty.
Edit: As suggested here is the VBA code for this:
Columns("A:A").Replace What:="""*", Replacement:="", LookAt:=xlPart
In case you want to keep your source data, you can also do it with a simple Excel formula in the next column. Assuming that your data is in column A, the following formula will return only the name: =LEFT(A1,SEARCH("""",A1)-1)
Press ctrl + f
, click on replace tab
, type *
in the find what
box and then click on replace all
. No need to put anything in replace
box. Here you are replacing everything after .
.