+ Reply to Thread
Results 1 to 13 of 13

Reverse words based on condition in excel?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Reverse words based on condition in excel?

    |Cell A                     |    Cell B                  |Cell C         |
    |---------------------------|----------------------------|---------------|
    |Thomas Reynaud best friend |best friend Thomas Reynaud  |Name           |
    |---------------------------|----------------------------|---------------|
    |Red Pink Blue Cube         |Cube Pink Blue Red          |               |
    |---------------------------|----------------------------|---------------|
    |start text end here        |text start end here         |Text           |
    |--------------------------------------------------------|---------------|
    I have excel sheet with data i want to reverse words Based on conditions as i given example above in column A i have data which i need to reverse in column B based on Column C. If column C contain name in value then column A test reverse like Column B. If column C Contain empty cell then Column a value change like column B as show in my example sheet above row 2. If contain other value in column C it reverse the Column A's value like result in Column B in row 3 above.

    I tried many formulas but they all work same not based on condition. mainly i tried this formula
    =MID(I2&" "&I2,FIND(" ",I2)+1,LEN(I2))
    and more similarly this one. Hope you understand my question thanks.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Reverse words based on condition in excel?

    May be
    Sub Test()
        Dim arr, X, I As Long
    
        arr = Range("A1:C" & Cells(Rows.Count, 1).End(xlUp).Row).Value
            For I = 1 To UBound(arr, 1)
                X = Split(arr(I, 1), " ")
                If arr(I, 3) = "Name" Then
                    arr(I, 2) = X(2) & " " & X(3) & " " & X(0) & " " & X(1)
                ElseIf arr(I, 3) = "" Then
                    arr(I, 2) = X(3) & " " & X(1) & " " & X(2) & " " & X(0)
                ElseIf arr(I, 3) = "Text" Then
                    arr(I, 2) = X(1) & " " & X(0) & " " & X(2) & " " & X(3)
                End If
            Next I
        Range("A1:C" & Cells(Rows.Count, 1).End(xlUp).Row).Value = arr
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    Quote Originally Posted by YasserKhalil View Post
    May be
    Sub Test()
        Dim arr, X, I As Long
    
        arr = Range("A1:C" & Cells(Rows.Count, 1).End(xlUp).Row).Value
            For I = 1 To UBound(arr, 1)
                X = Split(arr(I, 1), " ")
                If arr(I, 3) = "Name" Then
                    arr(I, 2) = X(2) & " " & X(3) & " " & X(0) & " " & X(1)
                ElseIf arr(I, 3) = "" Then
                    arr(I, 2) = X(3) & " " & X(1) & " " & X(2) & " " & X(0)
                ElseIf arr(I, 3) = "Text" Then
                    arr(I, 2) = X(1) & " " & X(0) & " " & X(2) & " " & X(3)
                End If
            Next I
        Range("A1:C" & Cells(Rows.Count, 1).End(xlUp).Row).Value = arr
    End Sub
    thanks dear its work great . thanks for sharing your knowledge .

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Reverse words based on condition in excel?

    You're welcome. Glad I can offer some help
    Please mark the thread as solved
    Regards

  5. #5
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    Quote Originally Posted by YasserKhalil View Post
    You're welcome. Glad I can offer some help
    Please mark the thread as solved
    Regards
    hi i got error some time "Run time error 9" subscript out of range any help in this why i got this error some time .

  6. #6
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    so what can do for this so it work with if their is dont have 4 words ? any idea , thanks

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

    Re: Reverse words based on condition in excel?

    If you don't have 4 words in Col.A, it will give you an error.

  8. #8
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    if column have less then 4 words and its name then no reverse and if have less then 4 words and its text reverse words with each other . thanks

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

    Re: Reverse words based on condition in excel?

    You showed us a clear logic for 4 words, now you need to show us a clear logic for others.
    2, 3 ,5, 6, 7 words. etc.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Reverse words based on condition in excel?

    I relied on the snapshot in first post and it was clear there are four words. Can you give more examples and the logic you intend to follow ?

  11. #11
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    Quote Originally Posted by YasserKhalil View Post
    I relied on the snapshot in first post and it was clear there are four words. Can you give more examples and the logic you intend to follow ?
    i tired and it work sometime even if cell have 3 words .. dont know how but its work .

  12. #12
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    Quote Originally Posted by notbanme View Post
    i tired and it work sometime even if cell have 3 words .. dont know how but its work .
    i got it how work even if cell have value 3 word because it have space include so its 4 .

  13. #13
    Registered User
    Join Date
    09-23-2016
    Location
    india
    MS-Off Ver
    2007
    Posts
    47

    Re: Reverse words based on condition in excel?

    is this possible this code add space at the end of values i mean if cell have 3 words code add space at the end of words and make it 4 . and if cell have 2 words it add 2 spaces so make it 4 . thanks

+ 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. Replies: 2
    Last Post: 06-20-2015, 06:11 AM
  2. Replies: 15
    Last Post: 10-12-2014, 08:53 AM
  3. Random Ditribution of Words with Condition
    By harshit91 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-20-2014, 07:06 AM
  4. [SOLVED] reverse the order of words with formula
    By Aquamore in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-15-2014, 10:22 PM
  5. Select worksheet based on condition & populate cell based on condition
    By beth1069 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2011, 01:27 PM
  6. Reverse Words order in sentence
    By ElmerS in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2010, 04:06 AM
  7. Replies: 2
    Last Post: 11-18-2005, 01:25 PM

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