+ Reply to Thread
Results 1 to 13 of 13

VBA: Wrapping text and transversing text between nubers or given speific text

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-01-2013
    Location
    IND
    MS-Off Ver
    Excel 2007
    Posts
    130

    VBA: Wrapping text and transversing text between nubers or given speific text

    I am looking for a VBA solution for
    1. transversed text and
    2. Wrapping text
    between numbers or after and before numbers or given specific text in between. Please find the attachment. My actual row is 1000 rows.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    05-01-2013
    Location
    IND
    MS-Off Ver
    Excel 2007
    Posts
    130

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    I know its the most easiest but ...

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    maybe
    Sub ertert11()
    Dim r As Range, s
    For Each r In Range("A1", Cells(Rows.Count, 1).End(xlUp)).SpecialCells(2).Areas
        s = Application.Transpose(r)
        r(1, 3).Resize(, UBound(s)).Value = s
    Next r
    End Sub
    Sub ertert22()
    Dim r As Range, s
    For Each r In Range("A1", Cells(Rows.Count, 1).End(xlUp)).SpecialCells(2).Areas
        s = Application.Transpose(r)
        r(1, 3).Value = Join(s, Chr(10))
    Next r
    End Sub

  4. #4
    Forum Contributor
    Join Date
    05-01-2013
    Location
    IND
    MS-Off Ver
    Excel 2007
    Posts
    130

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    If there is no blank rows in between data, it is transposing all
    Can't we transpose data under each numeric number (or given text) I think it can work without blank rows then.

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    try it
    Sub WrappingText()
    ertert33 True
    End Sub
    
    Sub NotWrappingText()
    ertert33 False
    End Sub
    Sub ertert33(bu As Boolean)
    Dim x, i&
    x = Range("A1", Cells(Rows.Count, 1).End(xlUp)).Value
    With CreateObject("System.Collections.ArrayList")
        For i = UBound(x) To 1 Step -1
            .Add x(i, 1)
            If Val(x(i, 1)) Then
                .Reverse
                If bu Then
                    Cells(i, 3) = Join(.toarray, Chr(10))
                Else
                    Cells(i, 3).Resize(, .Count) = .toarray
                End If
                .Clear
            End If
        Next i
    End With
    End Sub

  6. #6
    Forum Contributor
    Join Date
    05-01-2013
    Location
    IND
    MS-Off Ver
    Excel 2007
    Posts
    130

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    The transverse is not working
    1. if I am have only numbers 1, 2, 3, 4, .......
    2. If I have text with numbers in between 1, 2, 3, 4, ....... (1 above)

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

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    This should do
    Sub test()
        Dim x, i As Long
        With Range("a2", Range("a" & Rows.Count).End(xlUp))
            x = Filter(Evaluate("transpose(if(isnumber(left(" & .Address & ",1)+0)," & _
                    "row(1:" & .Rows.Count & "),char(2)))"), Chr(2), 0)
            If UBound(x) > -1 Then
                x = Split(Join(x, ",") & "," & .Rows.Count + 1, ",")
                For i = 0 To UBound(x) - 1
                    With .Rows(x(i) & ":" & x(i + 1) - 1)
                        .Cells(1).Copy .Cells(1, 3).Resize(, 2)
                        If .Rows.Count > 1 Then
                            .Cells(1, 3).Value = Join(Application.Transpose(.Value), vbLf)
                            .Copy
                            .Cells(1, 4).PasteSpecial Transpose:=True
                        End If
                    End With
                Next
            End If
        End With
    End Sub

  8. #8
    Forum Contributor
    Join Date
    05-01-2013
    Location
    IND
    MS-Off Ver
    Excel 2007
    Posts
    130

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    This line is giving problem: .Cells(1, 3).Value = Join(Application.Transpose(.Value), vbLf)

    I have got errors where my rows are as
    1
    1a
    bb2
    2
    2a
    3ab
    rrr
    sss

    After transpose the result aswell should be
    1 1a bb2
    2 2a 3ab rrr sss

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

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    Quote Originally Posted by sroysroy View Post
    This line is giving problem: .Cells(1, 3).Value = Join(Application.Transpose(.Value), vbLf)

    I have got errors where my rows are as
    1
    1a
    bb2
    2
    2a
    3ab
    rrr
    sss

    After transpose the result aswell should be
    1 1a bb2
    2 2a 3ab rrr sss
    I don't believe this at all!

    See
    Waht are you talking about.xlsm

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

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    If you are talking about the file I don't see, forget about the code.

  11. #11
    Forum Contributor
    Join Date
    05-01-2013
    Location
    IND
    MS-Off Ver
    Excel 2007
    Posts
    130

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    out of Curiosity I thought about changed input.

  12. #12
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    Can this one help ?



    Kind regards
    Leo
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA: Wrapping text and transversing text between nubers or given speific text

    Or maybe this, works with or without empty rows


    Kind regards
    Leo
    Attached Files Attached Files

+ 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. Wrap Text without Wrapping Text
    By manthux in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-07-2013, 03:33 PM
  2. Text Wrapping
    By Davidns in forum Excel General
    Replies: 1
    Last Post: 04-12-2013, 05:07 PM
  3. problem with text wrapping long text
    By TechRetard in forum Excel General
    Replies: 5
    Last Post: 03-14-2011, 03:05 PM
  4. Replies: 2
    Last Post: 05-06-2006, 01:15 PM
  5. [SOLVED] Text Wrapping
    By RhondaRoo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-17-2006, 10:40 PM
  6. [SOLVED] RE: Text Wrapping
    By JMB in forum Excel General
    Replies: 0
    Last Post: 07-28-2005, 10:05 PM
  7. Wrapping Text
    By lisacollins in forum Excel General
    Replies: 1
    Last Post: 01-28-2005, 11:18 AM
  8. wrapping text
    By lisacollins in forum Excel General
    Replies: 0
    Last Post: 01-27-2005, 03:34 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