简体   繁体   中英

Excel macro for quit data cleaning

I was wondering if someone could assist me with suggestions on how to clean up data in an Excel spread sheet.

I have a very long list I need to go through. Currently, I am copying a list of data (to get the names of a bunch of medications of interest) into Excel. But the problem is, each row of data has extraneous information that I don't need.

For example:

Fluoride Updated 7/10/13
Acetaminophen Updated 8/10/13

I'd like to create a macro that keeps only the first text (in the above example being fluoride and acetaminophen) and remove the rest.

Any suggestions? I've tried the "Find" and "Replace All" method so far, but of course as the dates differ for each medication, that's not really feasible.

Any assistance would be appreciated!

Thanks!

Since you seem at least a little flexible about using a macro maybe use formulae to preserve more flexibility for 'corner cases'. eg:

=LEFT(A1,FIND(" ",A1))  

in the case (unlikely?) where all drug names do not contain spaces, or perhaps more promising:

=LEFT(A1,FIND("Updated",A1)-2)  

where all entries include "Updated".

Sorting the results should indicate where parsing was not suitable and allow for further adjustment to suit.

Easiest way would be to create a macro that does a text to columns with a space as the delimeter

This assumes the data is in the first column of Sheet1

Dim shtWorking As Worksheet
Set shtWorking = Worksheets("Sheet1")
shtWorking.Columns(1).TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlNone, ConsecutiveDelimiter:=True, Tab:=False, Semicolon _
    :=False, Comma:=False, Space:=True, Other:=False, FieldInfo:=Array( _
    Array(1, 2), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM