Using Array Formulas in VBA

DHS100

Board Regular
Joined
May 21, 2006
Messages
147
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
What exactly do you mean by a 'VBA array'?
 
Upvote 0

dcardno

Well-known Member
Joined
Nov 20, 2002
Messages
558
Office Version
  1. 2013
Platform
  1. Windows
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,190,877
Messages
5,983,361
Members
439,840
Latest member
billy1989

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
Top