+ Reply to Thread
Results 1 to 5 of 5

Remove blank lines

  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    13

    Remove blank lines

    Greetings,

    I have a small spreadsheet that I export to a text file to run DNSCmd entries.

    I use (plagiarized from someone else because of lack of knowledge)...

    Sub createConfig()

    Application.ScreenUpdating = False

    ' Determine where to dave the config file
    configFile = Range("save_location").Value & Range("saved_file_name")

    ' Open the file for output
    fnum = FreeFile()
    Open configFile For Output As fnum

    ' Determine which config sheet to export

    Dim configType As String

    configType = "DNS"


    ' Now go to that config sheet and get the data and dump to file
    Sheets(configType).Select
    lastRow = Range("D40").End(xlUp).Row
    Range("D16").Select
    Do While ActiveCell.Row <= lastRow
    output = ActiveCell.Value

    Print #fnum, output
    ActiveCell.Offset(1, 0).Select

    Loop

    ' Close the file
    Close #fnum

    Sheets("DNS").Select
    Application.ScreenUpdating = True
    SaveMsg = "DNS Configuration file saved to " & configFile & vbNewLine & vbNewLine
    MsgBox Prompt:=SaveMsg, Title:="Configuration Compilation Complete"


    End Sub

    This works fine, however my output contains (potentially) blank lines as shown below...



    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01 /CreatePTR A 10.192.1.1
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-CE /CreatePTR A 10.190.1.45
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-PE /CreatePTR A 10.190.1.46

    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN1 /CreatePTR A 10.1.1.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN2 /CreatePTR A 10.1.2.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN3 /CreatePTR A 10.1.3.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN4 /CreatePTR A 10.1.4.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN1-HSRP /CreatePTR A 10.1.1.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN2-HSRP /CreatePTR A 10.1.2.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN3-HSRP /CreatePTR A 10.1.3.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN4-HSRP /CreatePTR A 10.1.4.254
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT02-VLAN1-HSRP /CreatePTR A 10.1.1.253
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT02-VLAN2-HSRP /CreatePTR A 10.1.2.253
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT02-VLAN3-HSRP /CreatePTR A 10.1.3.253
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT02-VLAN4-HSRP /CreatePTR A 10.1.4.253


    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTSW01 /CreatePTR A 10.1.1.240
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTSW02 /CreatePTR A 10.1.1.241
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTSW03 /CreatePTR A 10.1.1.242
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTSW04 /CreatePTR A 10.1.1.243

    Q: Is there a simple modification to what I have above to remove the blank lines?

    Thanks in advance. Heaps...

    ReeceB

  2. #2
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Remove blank lines

    Please wrap your code in Code Tags. Edit your post and select your code and click the "#" button in the editor toolbar.

    For your question, you can test ActiveCell to see if it is empty and only write to the file if it is not empty.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Remove blank lines

    Thanks for the lesson in forum etiquette and the solution.
    It worked (sort of).

    There appeared to be an issue if there were multiple blank cells.

    The code I am using is...

    Please Login or Register  to view this content.
    The result I get is...

    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01 /CreatePTR A 10.192.1.1
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-CE /CreatePTR A 10.190.1.45
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-PE /CreatePTR A 10.190.1.46
    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTRT01-VLAN1 /CreatePTR A 10.1.1.254











    DnsCmd dc1ns-ad01.hc.int RecordAdd hc.int MNTESTSW01 /CreatePTR A 10.1.1.240


    I have cell entries in d17-d20,d22,d36

    I appreciate your assistance.

    Hopefully I got the formatting correct this time.

    ReeceB

  4. #4
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Remove blank lines

    You may have cells that have been "cleared" by typing in a space character. Instead of using the IsEmpty function try using this function instead.
    Please Login or Register  to view this content.
    If this does not work, please upload a sample workbook. You can upload files by clicking on the "Go Advanced" button next to "Post Reply" and then clicking on the paperclip icon in the toolbar.

  5. #5
    Registered User
    Join Date
    01-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Remove blank lines

    You are an absolute legend. Thanks for taking the time to assist.
    You were spot on with your evaluation and solution.
    Again, many thanks.

    ReeceB

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] remove lines if a cell is blank
    By Christopherdj in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-01-2013, 10:08 PM
  2. How do I remove blank lines in the first column.
    By SWMagic in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-29-2013, 05:14 AM
  3. Create List and remove blank Lines
    By jamjam200 in forum Excel General
    Replies: 0
    Last Post: 01-22-2013, 12:30 PM
  4. Remove Blank Lines
    By Robotacha2010 in forum Excel General
    Replies: 5
    Last Post: 08-16-2010, 11:59 AM
  5. [SOLVED] Remove Blank Lines
    By Nigel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2005, 11:00 AM

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