+ Reply to Thread
Results 1 to 4 of 4

Export sheet to txt deleting blank rows

Hybrid View

  1. #1
    Registered User
    Join Date
    04-02-2012
    Location
    Brasil
    MS-Off Ver
    Excel 2010
    Posts
    20

    Export sheet to txt deleting blank rows

    I have a sheet that I need to export to a text file, but in my excel file some cells are blank because of the formula.
    On the text file those blank cells are still there and i have to manually delete them. To solve this problem I`m using this code

        For Each c In Range("A2:A2000")
            If c.Value <> "X" Then
                c.EntireRow.Delete
            End If
        Next
        
        Sheets("XPS_final").Select
        Sheets("XPS_final").Copy
        Rows("1:1").Select
        Selection.Delete Shift:=xlUp
        ActiveWorkbook.SaveAs Filename:="C:\Temporal\Para macros\" + Name + "_Final.txt", _
            FileFormat:=xlTextPrinter, CreateBackup:=False
        ActiveWindow.Close
        ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
        Sheets("variables").Select
    It works fine, but the For Each block takes a little bit to run. Any idea on how to improve this?

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Export sheet to txt deleting blank rows

    hi CassioGodinho, option to delete empty rows basing on A column values, A1 - header:

    Sub test()
    With Range("a1:a2000")
        .AutoFilter 1, "="
        .Offset(1).EntireRow.Delete
        .AutoFilter
    End With
    End Sub

  3. #3
    Registered User
    Join Date
    04-02-2012
    Location
    Brasil
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Export sheet to txt deleting blank rows

    Thanks man, it worked perfectly.

    Could you try to explain me what exactly is the code doing?

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Export sheet to txt deleting blank rows

    autofilter empty cells within the set range, delete autofiltered rows

+ 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