Results 1 to 4 of 4

Thread: Separate excel cell data into rows

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    1

    Separate excel cell data into rows

    I have data of multiple line in an excel cell, Separated by "Enter" (ASCII 13).
    By using VBA I want to trasfer each line in to separate excel row.
    e.g. Cell B2 contains data --
    VS6_AIO > 0 OR VS6_DIOE > 0
    VS6_QTY_B = VS6_AIO*2 IF VS6_AIO > 0 AND VS6_REDY = '2',
    VS6_QTY_B = VS6_AIO IF VS6_AIO > 0 AND VS6_REDY NE '2',
    VS6_QTY_B = VS6_FM IF VS6_FM > 0,
    VS6_QTY_B = VS6_FM*2 IF VS6_FM > 0 AND VS6_RPSI>'Y'

    I want to saparte it into row C2,C3,C4,C5,C6
    Thanks
    SK

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Separate excel cell data into rows

    Thread moved from the FAQ forum, which is not the place to post your questions.

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Separate excel cell data into rows

    Quote Originally Posted by kulkasac
    I have data of multiple line in an excel cell, Separated by "Enter" (ASCII 13).
    By using VBA I want to trasfer each line in to separate excel row.
    e.g. Cell B2 contains data --
    VS6_AIO > 0 OR VS6_DIOE > 0
    VS6_QTY_B = VS6_AIO*2 IF VS6_AIO > 0 AND VS6_REDY = '2',
    VS6_QTY_B = VS6_AIO IF VS6_AIO > 0 AND VS6_REDY NE '2',
    VS6_QTY_B = VS6_FM IF VS6_FM > 0,
    VS6_QTY_B = VS6_FM*2 IF VS6_FM > 0 AND VS6_RPSI>'Y'

    I want to saparte it into row C2,C3,C4,C5,C6
    Thanks
    SK
    Does this help?

    vb Code:
    1. Sub SplitMyData()
    2.  
    3. 'Replace Sheet1 below with the name of the sheet
    4. str1 = Sheets("Sheet1").Range("B2").Value
    5. MyPos = Split(str1, vbLf)
    6. For i = 0 To UBound(MyPos)
    7.     '(I+2) below will ensure that the data is populated
    8.     'from C2 onwards
    9.     Range("C" & (i + 2)).Value = MyPos(i)
    10.     'MsgBox MyPos(i)
    11. Next
    12.  
    13. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Separate excel cell data into rows

    here is some other code to do the same thing
    vb Code:
    1. arrdata = Split(Range("B2").Value, vbNewLine)
    2. Range("c2:c" & UBound(arrdata) + 2) = WorksheetFunction.Transpose(arrdata)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width