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
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    find words in a row and format

    Good Morning,

    I have a single row with data that contains fruits and weather they are fresh or canned. I would like to find all the occurences that start with letters ap and then format in columns.
    For example:
    apple fresh
    appricot canned
    I can find the words, but do not know how to get it in columns.
    Any help is appreciated.
    Thank you.
    codedreaner

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Can you post a sample file?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0
    Last edited by DocAElstein; 03-01-2024 at 02:58 PM. Reason: Removed Quote

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    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

  5. #5
    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

  6. #6
    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
  •