Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default variable as criteria in COUNTIF

Hi

This doesn't work (it runs, but gives a result of 0 instead of the
correct answer) when the user responds with 54161 (for example):

Sub HowMany()
Dim res As String
Dim myinput As String
myinput = InputBox("Enter the CPT Code...")
res = Evaluate("=CountIf(Ops, myinput)")
MsgBox (res)
End Sub

This does work:

Sub HowMany()
Dim res As String
Dim myinput As String
'myinput = InputBox("Enter the CPT Code...")
res = Evaluate("=CountIf(Ops, 54161)")
MsgBox (res)
End Sub

I've searched this group and googled, but can't find why or how to get
the VBA for COUNTIF to accept a variable as a criteria....

Any idea how to get around this ?

Thanks again

C L Snyder

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default variable as criteria in COUNTIF

Charles,

Try it this way:

res = Evaluate("=CountIf(Ops, " & myinput & ")")


I believe this way should also work:

res = WorksheetFunction.CountIf(Range("Ops"), myinput)


--
Hope that helps.

Vergel Adriano


"Charles L. Snyder" wrote:

Hi

This doesn't work (it runs, but gives a result of 0 instead of the
correct answer) when the user responds with 54161 (for example):

Sub HowMany()
Dim res As String
Dim myinput As String
myinput = InputBox("Enter the CPT Code...")
res = Evaluate("=CountIf(Ops, myinput)")
MsgBox (res)
End Sub

This does work:

Sub HowMany()
Dim res As String
Dim myinput As String
'myinput = InputBox("Enter the CPT Code...")
res = Evaluate("=CountIf(Ops, 54161)")
MsgBox (res)
End Sub

I've searched this group and googled, but can't find why or how to get
the VBA for COUNTIF to accept a variable as a criteria....

Any idea how to get around this ?

Thanks again

C L Snyder


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default variable as criteria in COUNTIF

I think I tried every permutation of "=", "&", etc but that one - it
works perfectly!

Thanks

CLS

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
More than one variable for Countif Carrie_Loos via OfficeKB.com Excel Worksheet Functions 14 May 5th 09 07:57 AM
countif using two variable Memphus01 Excel Discussion (Misc queries) 8 December 9th 08 07:37 PM
countif variable criteria neda5 Excel Discussion (Misc queries) 3 May 3rd 05 10:55 AM
Countif using format criteria not number criteria? Rumbla76 Excel Worksheet Functions 1 April 20th 05 05:38 AM
Countif using format criteria....not number criteria? Troy Excel Worksheet Functions 1 April 20th 05 04:50 AM


All times are GMT +1. The time now is 09:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"