+ Reply to Thread
Results 1 to 13 of 13

Return value only if all words are uppercase

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    4

    Question Return value only if all words are uppercase

    I have about 5000 rows with mixed upper & lower case words. I am trying to get only values if all words are upper-case. I have office 2013.
    Can anyone perhaps help?

  2. #2
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Return value only if all words are uppercase

    Do you mean if the first letter of the word is a capital or if all letters in the word are capitalised?

    Also, how many words in each cell?

  3. #3
    Registered User
    Join Date
    04-16-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Return value only if all words are uppercase

    Hi TKCZBW
    1.No not only first letter of word. It must be where the words are completely in uppercase.
    2.It differs, I can't say exactly.

  4. #4
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Return value only if all words are uppercase

    This should do it:

    Sub Test()
    Dim l As Integer
    Dim Text As String
    
    lastrow = ActiveSheet.UsedRange.Rows.Count
    
    For i = 1 To lastrow
        Text = Cells(i, 1).Value
        l = Len(Text)
        For x = 1 To l
        If Mid(Text, x, 1) Like "[A-Z]" Or Mid(Text, x, 1) Like " " Then
            Cells(i, 2).Value = "TRUE"
        Else
            Cells(i, 2).Value = "FALSE"
            Exit For
        End If
        Next x
    Next i
    End Sub
    It assumes all your input values are in row 'A', and will then output True/False in Row 'B'.

    Let me know if it works!
    Last edited by TKCZBW; 04-16-2014 at 05:38 AM. Reason: Extraneous variable

  5. #5
    Registered User
    Join Date
    04-16-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Return value only if all words are uppercase

    It worked beautifully ... thank you so much!
    (one day when I'm "all grown-up" I want to be able to do what you did, myself)
    Thank you thank you!

  6. #6
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Return value only if all words are uppercase

    Not at all, happy to help!

    We all started somewhere and we never stop learning (and forgetting) things.

    If I helped, can you mark this post as 'solved' and add to my reputation?

    Best,

    TKCZBW

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,051

    Re: Return value only if all words are uppercase

    Hi Petro, hoe gaan dit daar in die kaap? SA ex-pat here from PE and Klerksdorp

    Another option to consider withe be an IF() function build around a simple test to see if all letters in your string are upper case, something like...

    =IF(EXACT(UPPER(A1),A1),do-this,do-that)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  8. #8
    Registered User
    Join Date
    04-16-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Return value only if all words are uppercase

    Hi FDibbins - dit gaan goed hier in die Kaap! Net warm. Wonderlik ... PE & Klerksdorp..! Ek het familie in beide.
    Ek sukkel met die "if" - ek het ongelukkig nie hierdie ondervinding nie, ek wens ek het gehad. Jy gaan my asb moet leiding gee ..."do-this,do-that" hehe... ek het geen idee nie.

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Return value only if all words are uppercase

    =exact(upper(a1),a1)
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Return value only if all words are uppercase

    Martin, that's a much cleaner way than mine.

    Thanks for the tip!

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Return value only if all words are uppercase

    hmm ford beat me too it it funny my iphone didnt show all the thread

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,051

    Re: Return value only if all words are uppercase

    Petro, an IF() statement is made up of 3 parts, a test, option 1, option2.

    So you perform your test, then based on the results of that test, you either do option1 or you do option2.

    Based on your question...
    I am trying to get only values if all words are upper-case. I have office 2013
    if the value you want to return is in B2, and your text is in A2, then maybe something like this...
    =IF(EXACT(UPPER(A2),A2),B2,"") The "" will return a "blank" cell
    Last edited by FDibbins; 04-17-2014 at 09:27 AM. Reason: Thanks for the catch, sktneer :)

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Return value only if all words are uppercase

    if the value you want to return is in B2, and your text is in A2, then maybe something like this...
    =IF(EXACT(UPPER(A1),A1),B1,"") The "" will return a "blank" cell
    Shouldn't it be like this?
    If your text is in A2 and you want to return it in B2 only if it meets the criteria,

    In B2, try this....

    =IF(EXACT(UPPER(A2),A2),A2,"")
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

+ 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: 7
    Last Post: 06-05-2014, 02:50 AM
  2. How to uppercase selected words?
    By jgomez in forum Access Tables & Databases
    Replies: 5
    Last Post: 03-27-2012, 06:59 PM
  3. Extract uppercase words from string
    By agf12555 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2011, 11:30 AM
  4. Extract uppercase words from string
    By agf12555 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2011, 03:05 PM
  5. VB - Making first letters of words uppercase
    By Smurlos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2010, 08:10 PM

Tags for this Thread

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