Results 1 to 2 of 2

Replace "Enter" from a VBA code to split wrapped text into different cells/rows

Threaded View

AliceDB Replace "Enter" from a VBA... 06-22-2017, 06:24 AM
Kaper Re: Replace "Enter" from a... 06-22-2017, 06:58 AM
  1. #1
    Registered User
    Join Date
    06-22-2016
    Location
    Bucharest,Romania
    MS-Off Ver
    Office 2016
    Posts
    4

    Replace "Enter" from a VBA code to split wrapped text into different cells/rows

    Hello All, I need your advise, if it will be ok, to replace the "enter" character, from a VBA code, which split the data from wrapped text cells into different cells / rows.

    Please find below the code. This works fine, but I would like to know if it is feasible to replace the "enter" with some other character. Does any other character, ruin the macro functionality? How should I add it?

    With the current macro, users cannot use "enter" inside their text fields. If they start to submit enter and use more paragraphs inside the text field, the macro is not working ok - not taking all the data.
    Any thoughts on this?

    Thanks a lot

    Sub Test()
      Dim arrIn, arrLen, arrOut, totalRow As Long, i As Long, j As Long, k As Long, p As Long
      With Sheets("Sheet1")
        arrIn = .Range("A1").CurrentRegion.Value
        ReDim arrLen(1 To UBound(arrIn, 1))
      End With
      For i = 2 To UBound(arrIn, 1)
          For j = 1 To UBound(arrIn, 2)
              If Len(arrIn(i, j)) Then
                 arrIn(i, j) = Split(arrIn(i, j), vbLf)
                 k = UBound(arrIn(i, j)) + 1
                 If arrLen(i) < k Then arrLen(i) = k
              End If
          Next j
      Next i
      arrLen(1) = 1
      totalRow = 1
      For i = 2 To UBound(arrLen)
          totalRow = totalRow + arrLen(i)
      Next i
      ReDim arrOut(1 To totalRow, 1 To UBound(arrIn, 2))
      p = 1
      For i = 1 To UBound(arrIn, 1)
          For j = 1 To UBound(arrIn, 2)
              If IsArray(arrIn(i, j)) Then
                 For k = 0 To UBound(arrIn(i, j))
                     arrOut(p + k, j) = arrIn(i, j)(k)
                 Next k
              Else
                 arrOut(p, j) = arrIn(i, j)
              End If
           Next j
           p = p + arrLen(i)
      Next i
      With Sheets.Add(after:=Sheets(Sheets.Count))
        With .Range("A1").Resize(UBound(arrOut, 1), UBound(arrOut, 2))
          .Value = arrOut
          .EntireColumn.AutoFit
        End With
      End With
    End Sub
    Last edited by AliceDB; 06-22-2017 at 08:14 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Vba code to split data with delimited "," in separate rows
    By gaikwad.mm@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-26-2017, 02:26 AM
  2. Replies: 1
    Last Post: 03-31-2014, 08:39 PM
  3. [SOLVED] how to replace the "Alt-Enter" character in a cell with sway "@"
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-04-2014, 05:55 AM
  4. Find "TEXT 1" in a range and enter "TEXT 2" in the adjacent cell
    By madreag in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-28-2013, 05:34 PM
  5. code to replace 'Rows("31:31").Select' statement with variables
    By Ed_Collins in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-17-2012, 06:28 PM
  6. How do I split "A1B2" into "A1" and "B2" using text to column fun.
    By Jennifer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2005, 06:06 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