drom
Well-known Member
- Joined
- Mar 20, 2005
- Messages
- 527
- Office Version
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
Hi and Thanks in advance!
I have a Column with sentences and/or...
I am Trying to get using VBA how many of the cells in a range of cells (a column, Eg: A5:A1594)
I am trying to use:
wCell="Hello"
set Rng=range("A5:A1594")
So I am doing something wrong
I do not want to use for Each cell in Rng.cells ...
But I do not get the right answer
I have a Column with sentences and/or...
I am Trying to get using VBA how many of the cells in a range of cells (a column, Eg: A5:A1594)
- Have a string ending with: " " & "Hello"
- Have a string starting with: "Hello "
- Conmtaing the string : " Hello "
- Having the string with: "*" & "Hello" & "*" 'So Hello no matter where 'I know how to get this one
I am trying to use:
wCell="Hello"
set Rng=range("A5:A1594")
VBA Code:
xHowManyStartingWithHello = 0: xHowManyStartingWithHello = Application.WorksheetFunction.WorksheetFunction(Rng, "*" & " " & wCell) 'Should be: 53, I get = 0
xHowManyEndingWithHello = 0: xHowManyEndingWithHello = Application.WorksheetFunction.WorksheetFunction(Rng, wCell & " *") 'Should be: 5, I get = 0
xHowManyHelloInTotal = 0: xHowManyHelloInTotal = Application.WorksheetFunction.CountIf(Rng, "*" & wCell & "*") 'Should be: 64, I get = 64
xHowManyHelloInside = 0: xHowManyHelloInside = Application.WorksheetFunction.WorksheetFunction(Rng, "* " & wCell & " *" ) 'Should be: 6, I get = 0
So I am doing something wrong
I do not want to use for Each cell in Rng.cells ...
But I do not get the right answer