+ Reply to Thread
Results 1 to 3 of 3

VBA separate uppercase words from lowercase words.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-03-2017
    Location
    London
    MS-Off Ver
    2013
    Posts
    1

    VBA separate uppercase words from lowercase words.

    Hi everyone. Basically, I have a txt file with different words and each one has it's own row. I have to copy them using VBA from txt to Excel file and then separate the UPPERCASE and LOWERCASE words. Words that start with the UPPERCASE should be in column A, but words that start with LOWERCASE should be in column B.
    I have this code so far which copies the words from txt file to excel:

    Public Sub aaa()


    Dim i As Long, j As Long
    Dim myStr As String
    Dim Words() As String


    'CHECK THE FILE EXISTS, IF NOT QUIT
    If Dir("C:\Users\Robert\Desktop\ekselis\forexcel.txt") = "" Then
    MsgBox ("File not Found")
    Exit Function 'ADDED QUIT MESSAGE
    End If


    'FILE TO OPEN
    Open "C:\Users\Robert\Desktop\ekselis\forexcel.txt" For Input As #1


    'LOOP COUNTER
    i = 0


    'LOOP THROUGH FILE
    Do Until EOF(1)


    'READ A LINE
    Line Input #1, myStr


    'SEPERATE THE LINE BY WORDS
    Words = Split(myStr, " ")


    'LOOP THROUGH WORDS ARRAY
    For j = LBound(Words) To UBound(Words)


    'IF THE WORD IS NOT A ""
    If Words(j) <> "" Then


    'THEN PLACE THE WORD IN THE CELL
    ActiveCell.Offset(i, j) = Words(j)


    End If


    Next


    i = i + 1
    Loop




    Close #1


    End Function

    I`m not really sure how to organise the IF statements in a loop to complete my task... Thanks!

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,192

    Re: VBA separate uppercase words from lowercase words.

    'this will scan the column then set the upper/lower. run: SplitUpperLower
    '-----------
    Sub SplitUpperLower()
    '-----------
    Dim vRet
    range("A2").select
    While ActiveCell.Value <> ""
        vRet = TestCase(ActiveCell.Value)
        Select Case vRet
        Case "UPPER"
           ActiveCell.Offset(0, 1).Value = ActiveCell.Value
        Case "LOWER"
           ActiveCell.Offset(0, 2).Value = ActiveCell.Value
        End Select
        
        ActiveCell.Offset(1, 0).Select   'next row
    Wend
    End Sub
    
    '-----------
    private Function TestCase(pvWord)
    '-----------
    Dim vChr
    
    vChr = Left(pvWord, 1)
    Select Case Asc(vChr)
    Case 65 To 90
            'its upper case
      TestCase = "UPPER"
    Case 67 To 122
             'lower case
      TestCase = "LOWER"
    Case Else
             'neither ,not letter
      TestCase = "neither"
    End Select
    End Function

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA separate uppercase words from lowercase words.

    cross-posted http://www.vbaexpress.com/forum/show...owercase-words

+ 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. Return value only if all words are uppercase
    By technigirl in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-17-2014, 09:19 AM
  3. [SOLVED] VBA issue - trying to separate words with CAPITALS from Proper words
    By Eagle29 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-24-2013, 04:22 AM
  4. How to uppercase selected words?
    By jgomez in forum Access Tables & Databases
    Replies: 5
    Last Post: 03-27-2012, 06:59 PM
  5. Extract uppercase words from string
    By agf12555 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2011, 11:30 AM
  6. Extract uppercase words from string
    By agf12555 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2011, 03:05 PM
  7. 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

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