+ Reply to Thread
Results 1 to 6 of 6

Remove linespaces but not the lines in range of cells with text.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Remove linespaces but not the lines in range of cells with text.

    Hi. I have trying to make a macro to remove linespaces but not the lines in range of cells with text.
    Its in Sheet1 range A6 to A1000.
    Tried many solutions but they all remove and put it in one line which is not what i really want.

    Example.

    Remove the line spaces but not the lines also above



    this is a test from one cell

    Wanted result.

    Remove the line spaces but not the lines also above
    this is a test from one cell

    I cant figure it out and would be great to solve it.
    I have attached a test sheet to work with.
    Thanks in advance.
    Sincerely Abjac
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,487

    Re: Remove linespaces but not the lines in range of cells with text.

    Your column A (Before) and Column E (after) are the exact same.

  3. #3
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Remove linespaces but not the lines in range of cells with text.

    Hi Davesexcel.
    I just checked its not the same in column E there is linespaces in the text .
    Like this.
    -------
    Remove the line spaces but not the lines also above
    space
    Example this
    --------
    But i want this the space go away but not the line. In column E it look like this copied directly in here.

    Like this.
    -------
    Remove the line spaces but not the lines also above
    Example this
    No space
    --------
    You can see it in the upper bar. And here you can also remove the line space manually. But i have really many cells in this column thats why would like to have a macro.
    Sincerely Abjac
    Last edited by abjac; 06-25-2023 at 04:23 AM.

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Remove linespaces but not the lines in range of cells with text.

    Please try in B6 and copy down:
    Formula: copy to clipboard
    =SUBSTITUTE(A6,CHAR(10)&CHAR(13),"")
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Remove linespaces but not the lines in range of cells with text.

    Hi hansDouwe. And thanks for your answer. It seems to work well if i do it like that. Is there a way to put this in a macro directly in Exmple column A ?
    sincerely Abjac

  6. #6
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Remove linespaces but not the lines in range of cells with text.

    I can do it like this. Its a lets say extremely not nice solution but its working. If some can do this better would be nice.
    I paste formula into K6 and down the one provided here. With a macro.
    I use other formula to only show values. After i move all to column A6 and down and in the end i unwrap it also with macro.
    It look like below but very not nice but seems to be working.
    If some and i am sure can do this more easy would be great.
    Sincerely Abjac

    Sub formulas()
    Sheet1.Select
        Range("K6").Select
        ActiveCell.FormulaR1C1 = "=SUBSTITUTE(RC[-10],CHAR(10)&CHAR(13),"""")"
        Range("K6").Select
        Selection.AutoFill Destination:=Range("K6:K12"), Type:=xlFillDefault
        Range("K6:K2000").Select
        Range("A1").Select
    Call ChangingFormulasToValue
    End Sub
    Sub Move()
    Sheet1.Select
        Range("K6:K2000").Select
        Selection.Cut
        Range("A6").Select
        ActiveSheet.Paste
        Range("A1").Select
        Call wrap
    End Sub
    Sub wrap()
        Sheet1.Select
        Range("A6:A2000").Select
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        ActiveSheet.Rows("6:2000").RowHeight = 15
        Range("A1").Select
    End Sub
    Option Explicit
    
    Sub ChangingFormulasToValue()
    Sheet1.Select
    'Declaring variables
    Dim SourceRng As Range
    
    'Specify all cells in the active sheet as range
    Set SourceRng = Range("K6", Range("K6").SpecialCells(xlCellTypeLastCell))
    
    'Assigning only value of the cell skipping formula of the cell
    SourceRng.Value = SourceRng.Value
    Call Move
    End Sub
    Last edited by abjac; 06-25-2023 at 06:13 AM.

+ 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 last three lines of text files
    By ussenterprise in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-26-2019, 05:06 PM
  2. [SOLVED] Convert text to data and remove specific lines
    By SubwAy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-13-2017, 07:20 AM
  3. [SOLVED] Remove lines based on cell value (remove lines in range, not entire row)
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-27-2015, 07:31 AM
  4. [SOLVED] Processing multiple lines of text in range of cells which contain CR and LF
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-17-2015, 01:24 PM
  5. [SOLVED] Cocatenate Range of Cells in a column, remove blank cells, and stack text in a cell
    By paxile2k in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-22-2014, 07:47 PM
  6. [SOLVED] Macro neede to open text files from folder and remove all the lines except specific lines
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-07-2014, 02:44 AM
  7. Formulas to remove specific lines of text from a spreadsheet
    By visionwindowfilms in forum Excel General
    Replies: 11
    Last Post: 02-28-2010, 06:04 PM

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