ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using countif into a formula (https://www.excelbanter.com/excel-programming/343645-using-countif-into-formula.html)

fuzzy

using countif into a formula
 
I want to put a formula in a cell, to check if a range of cells
contains one character.
I think it seems like

ActiveCell.Formula = "=" & "COUNTIF(" & first_cell & ":" & last_cell &
";" & ""P"" & ")"

where first_cell and last_cell are the bounds of a range
and "P" is the character I want to check if it exists

but it does not work


XPete

using countif into a formula
 
This worked for me
;-)

Dim myRange As Range
Dim Formula As String

Set myRange = Worksheets("Sheet1").Range("A1:C10")

Formula = Application.WorksheetFunction.CountIf(myRange, "P")

MsgBox Formula


Mike Fogleman

using countif into a formula
 
One method is:

Sub Frmula()
Dim firstcell As String
Dim lastcell As String
firstcell = Range("A1").Address
lastcell = Range("A13").Address
Range("B1").Formula = "=COUNTIF(" & firstcell & ":" & lastcell & ",""p"")"
End Sub

Mike F

"fuzzy" wrote in message
oups.com...
I want to put a formula in a cell, to check if a range of cells
contains one character.
I think it seems like

ActiveCell.Formula = "=" & "COUNTIF(" & first_cell & ":" & last_cell &
";" & ""P"" & ")"

where first_cell and last_cell are the bounds of a range
and "P" is the character I want to check if it exists

but it does not work




Bob Phillips[_6_]

using countif into a formula
 
Get the address of the cells, first_cell.address and last_cell.address

--

HTH

RP
(remove nothere from the email address if mailing direct)


"fuzzy" wrote in message
oups.com...
I want to put a formula in a cell, to check if a range of cells
contains one character.
I think it seems like

ActiveCell.Formula = "=" & "COUNTIF(" & first_cell & ":" & last_cell &
";" & ""P"" & ")"

where first_cell and last_cell are the bounds of a range
and "P" is the character I want to check if it exists

but it does not work





All times are GMT +1. The time now is 10:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com