Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete data in cell after specific character

Tags:

excel

vba

I have data in cells A1:A1000. It is a list of names followed by a small note, like this:

  • sam" fast
  • nick" long
  • tom" quick

They all have " and a space after the names and then the note. What I am trying to do is delete the everything after the name.

I was playing around with macros to try and do this, but could not get anything to work. Any idea how I might do this?

like image 295
sam Avatar asked Dec 19 '12 17:12

sam


People also ask

How do I remove all text before after a specific character?

Press Ctrl + H to open the Find and Replace dialog. In the Find what box, enter one of the following combinations: To eliminate text before a given character, type the character preceded by an asterisk (*char). To remove text after a certain character, type the character followed by an asterisk (char*).


1 Answers

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
like image 155
ApplePie Avatar answered Sep 29 '22 09:09

ApplePie