+ Reply to Thread
Results 1 to 4 of 4

moving cell contents

Hybrid View

Mikeyd1 moving cell contents 04-16-2011, 10:37 AM
barryleajo Re: moving cell contents 04-16-2011, 01:11 PM
jaslake Re: moving cell contents 04-16-2011, 02:45 PM
Leith Ross Re: moving cell contents 04-16-2011, 03:40 PM
  1. #1
    Registered User
    Join Date
    04-16-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    2

    moving cell contents

    I need to have the data from a text file rearranged to show each product in one row.

    I attached the original file and changed the first 2 lines to show what is wanted.
    Attached Files Attached Files
    Last edited by Mikeyd1; 04-16-2011 at 12:20 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: moving cell contents

    Can you get your text file to output without the blank rows between your data fields?
    Then select each data record set, cut and paste transpose?

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: moving cell contents

    Hi Mikeyd1
    Looking at your file, it appears that each item has either 7 or 6 rows of data associated with the item. Will this ALWAYS be true?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: moving cell contents

    Hello Mikeyd1,

    Welcome tot he Forum!

    The macro below will convert the data from horizontal to vertical. The converted text is copied over to a second sheet named "Results". The macro was written to start at cell "A13". Your actual file probably starts at a different cell. Change the starting cell marked in bold in the macro below before running this on the real file. Also, be sure to add another worksheet and name it "Results" in your workbook with the original text. There is button on the "Results" worksheet to run the macro.

    Sub TransposeText()
    
      Dim Data() As Variant
      Dim DstRng As Range
      Dim DstWks As Worksheet
      Dim I As Long, N As Long, R As Long
      Dim RngEnd As Range
      Dim SrcRng As Range
      Dim SrcWks As Worksheet
      
        Set SrcWks = Worksheets("utf8BQ2j")
        Set DstWks = Worksheets("Results")
        
          Set SrcRng = SrcWks.Range("A13")
          Set RngEnd = SrcWks.Cells(Rows.Count, SrcRng.Column).End(xlUp)
          
          If RngEnd.Row < SrcRng.Row Then Exit Sub
          
          Set SrcRng = SrcWks.Range(SrcRng, RngEnd)
          
          Set DstRng = DstWks.Range("A2")
          DstWks.UsedRange.Offset(1, 0).ClearContents
          
            ReDim Data(1 To (SrcRng.Rows.Count \ 2), 1 To 7)
            
            For R = 1 To SrcRng.Rows.Count Step 2
              N = N Mod 7
              If N = 0 Then I = I + 1
              Data(I, N + 1) = SrcRng.Item(R)
              N = N + 1
            Next R
            
          DstRng.Resize(I, 7).Value = Data
          
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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