Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2016, 03:40 PM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Smile VBA formulas

How to create VBA that performs COUNTIF/COUNTIFS?
I want a VBA for S2 to =COUNTIF(A:A,"<>")-1
and to be formatted as a number with no decimal
Reply With Quote
  #2  
Old 01-15-2016, 02:38 AM
Debaser's Avatar
Debaser Debaser is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

You need:
Code:
With Range("S2")
.Value2 = Application.Countif(Range("A:A"), "<>")
.numberformat = "#,##0"
End With
Reply With Quote
  #3  
Old 01-15-2016, 08:21 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Talking

Thanks Debaser!
that worked great.
Reply With Quote
  #4  
Old 01-15-2016, 10:38 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

how to use it with more than one function

With Range("M2")
.Value2 = Application.CountIfs(Range("I:I"), "5",("C:C"),"OPEN"
.NumberFormat = "#,##0"
End With

The problem now is M2 = #VALUE!
Reply With Quote
  #5  
Old 01-18-2016, 02:35 AM
Debaser's Avatar
Debaser Debaser is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

You didn't repeat the Range call:

Code:
.Value2 = Application.CountIfs(Range("I:I"), "5",Range("C:C"),"OPEN")
Reply With Quote
  #6  
Old 01-18-2016, 04:52 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

Thanks again. That worked great again.
I have one more J2 = A2.
i would like the value from A2 to populate J2
Reply With Quote
  #7  
Old 01-18-2016, 05:05 AM
Debaser's Avatar
Debaser Debaser is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

That's just:
Code:
Range("J2").Value2 = Range("A2").Value2
Reply With Quote
  #8  
Old 01-18-2016, 05:12 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

Thanks for the quick reply. Worked great.
You are awesome
Reply With Quote
  #9  
Old 01-18-2016, 10:31 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

is this correct? I get an answer of 0
With Range("AE2")
.Value2 = Application.CountIfs(Range("N:N"), "4", Range("G:G"), "OPEN", Range("O:O"), ">0")
.NumberFormat = "#,##0"
End With

But with this in a cell I get an answer of 4
=COUNTIFS(G:G,"OPEN",N:N,"4",O:O,">0")
Reply With Quote
  #10  
Old 01-19-2016, 02:08 AM
Debaser's Avatar
Debaser Debaser is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

Can you post a workbook that shows the problem?
Reply With Quote
  #11  
Old 01-19-2016, 05:00 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

Here it is but not sure if it will help. It connects to a SQL database and pulls information that the VBA uses
Reply With Quote
  #12  
Old 01-19-2016, 05:02 AM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

I hope this one has the attachment
Attached Files
File Type: zip MMR - 13Jan2016 - Copy - Copy.zip (530.0 KB, 8 views)
Reply With Quote
  #13  
Old 01-19-2016, 08:15 AM
Debaser's Avatar
Debaser Debaser is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

There are no open items in that workbook so it's hard to disagree with the code.
Reply With Quote
  #14  
Old 02-01-2016, 01:58 PM
zhead zhead is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 64bit
Advanced Beginner
VBA formulas
 
Join Date: Mar 2015
Location: Texas
Posts: 32
zhead is on a distinguished road
Default

Sorry for the delay but work got me humping. Thanks for everything.
i have another question. This code works great but when i click on the cell on the worksheet the formula bar shows the formula. and when i copy this cell to another sheet the formula copies instead of the value.

Range("AC3").Formula = ("=IFERROR(AD2/Y2,0)")
Range("AC3").Select
Selection.NumberFormat = "0%"
Reply With Quote
  #15  
Old 02-02-2016, 01:38 AM
Debaser's Avatar
Debaser Debaser is offline VBA formulas Windows 7 64bit VBA formulas Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

Well, yes it would - you put a formula in the cell. That's how Excel works. You either paste special - Values when you want to put the value somewhere else, or you convert the formula to a value after you input it.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Right and Len formulas together PDGood Excel 4 11-20-2015 06:50 AM
formulas MSA5455 Excel 3 12-19-2014 01:50 AM
Help with IF or ELSE Formulas tsaladyga Excel 4 07-23-2014 09:04 AM
Need help with formulas please paul_pearson Excel 0 03-20-2013 06:51 AM
VBA formulas IF Formulas mizzamzz Excel 1 07-08-2010 02:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft