Using Array Formulas in VBA

DHS100

Board Regular
Joined
May 21, 2006
Messages
149
Hi,

I have a VBA Array that holds various sentences. I need to know how many words are in the entire array. If this were on a normal spreadsheet I'd use the formula:

{=(SUM(LEN(Test))-SUM(LEN(SUBSTITUTE(Test," ",""))))+COUNTA(Test)}

How would I do this on a VBA array?

Many thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
What exactly do you mean by a 'VBA array'?
 
Upvote 0
If the VBA array is Words(), with each array entry holding a string, you could try (air code)

for i = 1 to ubound(words)
if len(Words(i)) > 0 then
iCount = iCount + Len(Words(i)) - Len(worksheetfunction.substitute(Words(i)," ","")) + 1
end if
next i
...

I am not sure if there is a VBA equivalent of "substitute" - if so, that will probably be faster; adapt the lower bound of Words() depending on your option base setting.
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,666
Members
448,977
Latest member
moonlight6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top