Consulting

Results 1 to 6 of 6

Thread: VBA - character counting analysis

  1. #1

    VBA - character counting analysis

    hello,

    i need a vba macro that do text analysis under some constraints

    let's take a workbook with 2 worksheets : "text to analyze" tab and "Linguistic analysis" tab

    on the "text to analyze" tab, you will enter a text on A1 cell

    on the "Linguistic analysis" tab you will get statistical data like number of letters, vowels, most used words in the text etc...

    i made an example file of final result i will like to get :
    https://docs.google.com/spreadsheets...f=true&sd=true

    there is constraints to follow that you can find and read in the 3rd tab of the workbook linked above and some purple text on "Linguistic analysis" tab

    code with line comments will help much

    Thank you for your help !

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Welcome to VBAX Aurelian_. I must caution you here as to the extent of the assistance required here.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    This should hopefully count the number of words in a cell.

    =IF(A1="", 0,LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1)
    
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Counting Characters in a Cell. This will include all characters including spaces.
     =Len(A1)
    Counting Characters in a cell not including spaces
     =Len(Substitute(A1,"" "",""))
    Count the occurrences of a particular character in a Cell
     =Len(A1)-Len(Substitute(A1,"A",""))
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    hello,

    so i did all the code trying to follow strictly the constraints and it works on my side

    here is the vba code :
    https://drive.google.com/file/d/1cFI...usp=drive_link

    to apply on this test file, you have just to copy-paste code above in the vba Excel coding sheets on the test file linked below and run it after you save the test file as .xlsm to allow macro :
    https://docs.google.com/spreadsheets...f=true&sd=true

    But as you can see there is 3 macro :
    first macro answer question 1 to 3 thanks to functions/end functions
    the second macro answer question 4
    the third macro answer question 5

    can you help me to make one macro of this three ones by transforming macro 2 and macro 3 into functions ? Thus i will have only one macro button that will answer the 5 questions at once.

    Thank you !
    Last edited by aurelien_; 01-01-2024 at 07:21 AM.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    To get you started, you could do something like this
    It uses your functions to add information to the second worksheet
    You'll need to add the rest

    I added a command buttion to run the sub

    Also, I added your data and macro to make a XLSM workbook and attached it

    It's MUCH easier if you do it that way instead of Google docs, etc. so PLEASE next time


    Option Explicit
    
    
    Dim wsText As Worksheet
    Dim wsAnalysis As Worksheet
    Dim sText As String
    
    
    
    
    Sub SuperSub()
    
    
        Set wsText = Worksheets("Texte à analyser")
        sText = wsText.Cells(1, 1).Value
        
        Set wsAnalysis = Worksheets("Analyse linguistique")
        
        With wsAnalysis
        
            .UsedRange.Clear
            .Cells(1, 1).Value = "Number of letters in a string, ignoring punctuation, spaces and numbers"
            .Cells(1, 2).Value = NombreDeLettres(sText)
            
            .Cells(2, 1).Value = "Number of vowels in a string, ignoring punctuation, spaces and numbers"
            .Cells(2, 2).Value = NombreDeVoyelles(sText)
            
        End With
            
            
        MsgBox "Done"
    
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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