Godders199
Active Member
- Joined
- Mar 2, 2017
- Messages
- 313
- Office Version
- 2013
Hello, I am trying to find the vba to count the number ofwords in a cell, and have it run down to the last row.
Manually I have worked out the formula which is which iscurrently in column AB
=LEN(TRIM(P2))-LEN(SUBSTITUTE(P2," ",""))+1
I have been searching the internet, and found a code likethis, but playing about I can not get it to work
Sheets("submissions").Select
Dim dic As Object, cell As Range, temp As Variant
Dim i As Long
Set dic = CreateObject("scripting.dictionary")
With dic
For Each cell InRange("p1" & Cells(Rows.count, "A").End(xlUp).Row)
.RemoveAll
IfLen(cell.Value) > 0 Then
temp =Split(cell.Value, " ")
For i = 0To UBound(temp)
If Not.Exists(temp(i)) Then .Add temp(i), temp(i)
Next i
cell.Value= Join(.Keys, " ")
End If
Next cell
End With
Just wondered if anyone has any examples of code they could letme see and amend to fit my requirements.
Thanks
Manually I have worked out the formula which is which iscurrently in column AB
=LEN(TRIM(P2))-LEN(SUBSTITUTE(P2," ",""))+1
I have been searching the internet, and found a code likethis, but playing about I can not get it to work
Sheets("submissions").Select
Dim dic As Object, cell As Range, temp As Variant
Dim i As Long
Set dic = CreateObject("scripting.dictionary")
With dic
For Each cell InRange("p1" & Cells(Rows.count, "A").End(xlUp).Row)
.RemoveAll
IfLen(cell.Value) > 0 Then
temp =Split(cell.Value, " ")
For i = 0To UBound(temp)
If Not.Exists(temp(i)) Then .Add temp(i), temp(i)
Next i
cell.Value= Join(.Keys, " ")
End If
Next cell
End With
Just wondered if anyone has any examples of code they could letme see and amend to fit my requirements.
Thanks