+ Reply to Thread
Results 1 to 6 of 6

Remove space from text output

Hybrid View

  1. #1
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Remove space from text output

    Hi,
    I have this small macro which saves results of two columns in excel to a text file - each 5 seconds. It separates the columns with the space- but for some reason it adds the space BEFORE 1st column. I wonder if it can be changed to remove the first SPACE:

    Sub TEST()
        Dim c As Range, r As Range
        Dim output As String
        Calculate
        For Each r In Range("A1:B20").Rows
            For Each c In r.Cells
                output = output & " " & c.Value
            Next c
            output = output & vbNewLine
        Next r
        Open "C:\DATA\signals.txt" For Output As #1
        Print #1, output
        Close
    End Sub
    Thanks a lot!
    Last edited by zealot; 10-06-2019 at 03:39 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Please help modify macro

    Try change
        Print #1, output
    To
        Print #1, LTrim(output)

  3. #3
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Please help modify macro

    Or change this line:
    output = output & " " & c.Value
    to this:
    output = output & c.Value & " "
    Beth.

  4. #4
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Please help modify macro

    wonderful - this seems to work - can you also help me remove the tab after the last column?

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Please help modify macro

    It was a careless look....
    Sub TEST()
        Dim c As Range, r As Range
        Dim output As String
        Calculate
        Open "C:\DATA\signals.txt" For Output As #1
            For Each r In Range("A1:B20").Rows
                For Each c In r.Cells
                    output = output & " " & c.Value
                Next c
                Print #1, LTrim(output)
                output = ""
            Next r
        Close #1
    End Sub

  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,627

    Re: Please help modify macro

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

+ 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] Modify macro if found empty cell to do nothing and expand the range of macro
    By oeyandyprawira in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-15-2018, 03:44 AM
  2. Modify macro to only look at three ws not all
    By 3345james in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2015, 07:06 PM
  3. Replies: 2
    Last Post: 11-03-2014, 12:06 PM
  4. Macro Help - Modify macro to save as to specific location
    By scoochUM in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-30-2014, 04:10 PM
  5. Help to modify a macro
    By VKS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2013, 05:27 AM
  6. Stop Macro, Check Cells & Modify if Necessary, Resume Macro
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2009, 07:39 AM
  7. Replies: 3
    Last Post: 08-11-2008, 09:21 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