+ Reply to Thread
Results 1 to 2 of 2

Set Const Delimiter as line break (non-string)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-07-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    6

    Set Const Delimiter as line break (non-string)

    Hi,

    I'm using the below code to break some cells into rows. Each cell contains multiple lines (using Alt+Enter), which I want to split out into individual rows. The VBA code works well, however I cannot work out how to change the Const Delimiter value on line 3, to represent a "line break" as it is not a string value. Can this be done? Or should I simply add a string delimiter to the end of each row. This would be a pain, but manageable.

    Sub RedistributeData()
      Dim X As Long, LastRow As Long, A As Range, Table As Range, Data() As String
      Const Delimiter As String = ""
      Const DelimitedColumn As String = "C"
      Const TableColumns As String = "A:O"
      Const StartRow As Long = 8
      Application.ScreenUpdating = False
      LastRow = Columns(TableColumns).Find(What:="*", SearchOrder:=xlRows, _
                SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
      For X = LastRow To StartRow Step -1
        Data = Split(Cells(X, DelimitedColumn), Delimiter)
        If UBound(Data) > 0 Then
          Intersect(Rows(X + 1), Columns(TableColumns)).Resize(UBound(Data)).Insert xlShiftDown
        End If
        If Len(Cells(X, DelimitedColumn)) Then
          Cells(X, DelimitedColumn).Resize(UBound(Data) + 1) = WorksheetFunction.Transpose(Data)
        End If
      Next
      LastRow = Cells(Rows.Count, DelimitedColumn).End(xlUp).Row
      On Error Resume Next
      Set Table = Intersect(Columns(TableColumns), Rows(StartRow).Resize(LastRow - StartRow + 1))
      If Err.Number = 0 Then
        Table.SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
        Columns(DelimitedColumn).SpecialCells(xlFormulas).Clear
        Table.Value = Table.Value
      End If
      On Error GoTo 0
      Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Set Const Delimiter as line break (non-string)

    This should work

      Const Delimiter = vbLf
    Cheers
    Andy
    www.andypope.info

+ 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] Macro to separate the string of texts (with line break) and paste them in every cells (2)
    By fantasylo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2016, 02:28 PM
  2. [SOLVED] Macro to separate the string of texts (with line break) and paste them in every cells
    By fantasylo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-08-2016, 11:10 PM
  3. Expected End of Line; Trying to break up string block in VBEditor
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-05-2012, 02:28 AM
  4. Split string by line break into array
    By kennychung in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2009, 12:18 PM
  5. [SOLVED] Break cell into multiple lines by line break
    By Chia in forum Excel General
    Replies: 1
    Last Post: 08-20-2006, 01:40 AM
  6. how to declare Pub Const String Array ?
    By dick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2005, 02:05 PM
  7. Replies: 2
    Last Post: 06-14-2005, 02:05 PM

Tags for this Thread

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