Results 1 to 6 of 6

Thread: find words in a row and format

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Give this macro a try...

    Code:
    Sub RearrangeFruits()
      Dim X As Long, LastColumn As Long, Arr As Variant
      Const StartCell As String = "K1"
      Const StartOutputCell As String = "A4"
      LastColumn = Cells(Range(StartCell).Row, Columns.Count).End(xlToLeft).Column
      Arr = Range(StartCell, Cells(Range(StartCell).Row, LastColumn))
      Range(StartOutputCell).Resize(, 2).Value = Array("Fruit", "Quantity")
      For X = 1 To UBound(Arr, 2) Step 5
        With Range(StartOutputCell)
          .Offset(Int(1 + (X - 1) / 5), 0) = Arr(1, X + 1)
          .Offset(Int(1 + (X - 1) / 5), 1) = Arr(1, X + 3)
          .Offset(Int(1 + (X - 1) / 5), 2) = Arr(1, X + 4)
        End With
      Next
    End Sub
    NOTE: You will need to adjust the two constants (the Const statements) to reflect your actual start of data (I used K1 and A4 because that is where you showed them to be in your sample file).
    Last edited by bakerman; 11-25-2013 at 05:31 AM. Reason: Removed Quote

  2. #2
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0
    Thank you so much. It did work!
    I would like to know if you can explain this line to me?
    LastColumn = Cells(Range(StartCell).Row, Columns.Count).End(xlToLeft).Column
    Thanks again,

    codedreaner
    Last edited by bakerman; 11-25-2013 at 05:28 AM. Reason: Removed quote

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Thank you I understand it now

    I went through it several times, I understand now.
    Thanks again,

    codedreamer
    Last edited by bakerman; 11-25-2013 at 05:29 AM. Reason: No need to quote when answering to previous post

Similar Threads

  1. Find the last row in a range
    By PcMax in forum Excel Help
    Replies: 7
    Last Post: 03-22-2013, 03:46 AM
  2. Find Last Used Row In A Column Using Long Variable
    By xander1981 in forum Excel Help
    Replies: 2
    Last Post: 01-27-2013, 08:53 PM
  3. Vba Code to find value and paste on certain row
    By jwitte in forum Excel Help
    Replies: 3
    Last Post: 11-28-2012, 08:52 PM
  4. Find the First or Last So Many Words in a Text String
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 6
    Last Post: 06-21-2012, 09:42 PM
  5. Find Last Used Row In Column
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 06-04-2012, 07:40 AM

Posting Permissions

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