+ Reply to Thread
Results 1 to 11 of 11

Delete Unwanted Data

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Search and destroy!!

    Give this a try:
    Option Explicit
    
    Sub ImportObjectList()
    'Author:    Jerry Beaucaire
    'Date:      9/16/2010
    'Summary:   Import a text file and extract/format specific data
    Dim fName As String
    Dim LR As Long
    
    'Select a file
        With Application.FileDialog(msoFileDialogOpen)
            .AllowMultiSelect = False
            .Filters.Add "All Files", "*.*"        'everything
            .Filters.Add "Text Files", "*.txt", 1  'default
            .Show
            If .SelectedItems.Count > 0 Then
                fName = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        
    Application.ScreenUpdating = False
    'Import the file
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fName, _
            Destination:=Range("A1"))
            .Name = "ame--"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(2)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        
    LR = Range("A" & Rows.Count).End(xlUp).Row
    Range("B1:B" & LR).FormulaR1C1 = _
            "=IF(OR(ISNUMBER(SEARCH({""Information on"",""SEGMENT LENGTH""}, RC[-1]))), RC[-1], 1)"
    Columns("B:B").Select
        Selection.SpecialCells(xlCellTypeFormulas, 1).Select
        Selection.EntireRow.Delete
        Range("A1").Insert xlShiftDown
        Columns("B:B").Value = Columns("B:B").Value
        Range("A1:B1").Value = [{"OBJECTS","SEGMENT LENGTH"}]
        Columns("B:B").Replace What:="SEGMENT LENGTH = ", Replacement:="", LookAt:= _
            xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Range("A1").AutoFilter Field:=1, Criteria1:="=SEGMENT*"
        Range("A2:A" & LR).EntireRow.Delete xlShiftUp
        Range("A1").AutoFilter
        Range("A1").AutoFilter Field:=2, Criteria1:="=Informa*"
        Range("B2:B" & LR).ClearContents
        ActiveSheet.AutoFilterMode = False
        Columns("A:B").EntireColumn.AutoFit
        Columns("B:B").EntireColumn.AutoFit
        Range("A1:B1").Font.Bold = True
        Range("A2").Select
        ActiveWindow.FreezePanes = True
    
    Application.ScreenUpdating = True
    End Sub
    Last edited by JBeaucaire; 09-16-2010 at 12:07 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  2. #2
    Registered User
    Join Date
    09-16-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Search and destroy!!

    -----------------------------
    Last edited by lweng; 09-16-2010 at 11:37 AM.

  3. #3
    Registered User
    Join Date
    09-16-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Search and destroy!!

    I got it working now! Thanks that’s exactly what I need. I appreciate your help. Could you make it so It deletes the (string) off the back side of the segment length column? And add a column with the NAME? Thank you for your help!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1