Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Lista Forumurilor Pe Tematici
|
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login
POZE MRRRR'S FORUM (VIEW ONLY)
Nu sunteti logat.
|
Nou pe simpatie: deiutza20 Profile
| Femeie 21 ani Bacau cauta Barbat 21 - 44 ani |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 787
|
|
Sub CountWords()
Dim WordCount As Long Dim Rng As Range Dim S As String Dim N As Long
For Each Rng In ActiveSheet.UsedRange.Cells S = Application.WorksheetFunction.Trim(Rng.Text) N = 0 If S <> vbNullString Then N = Len(S) - Len(Replace(S, " ", "")) + 1 End If WordCount = WordCount + N Next Rng
MsgBox "Words In ActiveSheet Sheet: " & Format(WordCount, "#,##0") End Sub
|
Source:
|
|
pus acum 1 an |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 787
|
|
The following macro was made by ChatGPT and includes a timer that calculates how long it took the macro to run. The macro below is a bit slower than the one from post #1.
' written by ChatGPT: Sub CountWords_ChatGPT()
Dim startTime As Double Dim endTime As Double
startTime = Timer
Dim i As Long Dim j As Long Dim count As Long Dim cell As Range count = 0 For i = 1 To ActiveSheet.UsedRange.Rows.count For j = 1 To ActiveSheet.UsedRange.Columns.count Set cell = ActiveSheet.Cells(i, j) If Len(cell.Value) > 0 Then count = count + Len(cell.Value) - Len(Replace(cell.Value, " ", "")) + 1 End If Next j Next i
endTime = Timer
MsgBox "There are " & count & " words in the active sheet." & vbCrLf & _ "And the macro took " & endTime - startTime & " seconds to run."
End Sub |
|
|
pus acum 1 an |
|