#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default COUNTIF VBA

Hello - I wanted to incorporate a COUNTIF in VBA (not onto the spreadsheet) that
will precede this code. I would like the COUNTIF to first assess whether an instance of MISC appears in the cells of column 14. If TRUE, then proceed with the code. If FALSE, then skip this code and continue with the next step in the routine (does not exit the routine - there are further routine steps to follow).
Thank you very much in advance!

Worksheets("Check").Range("A1").AutoFilter Field:=14, Criteria1:="MISC"
Application.DisplayAlerts = False
ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
Application.DisplayAlerts = True
ActiveSheet.ShowAllData
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default COUNTIF VBA

Hi,

Am Thu, 3 Mar 2016 13:23:21 -0800 (PST) schrieb Merritt Ave:

Worksheets("Check").Range("A1").AutoFilter Field:=14, Criteria1:="MISC"
Application.DisplayAlerts = False
ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
Application.DisplayAlerts = True
ActiveSheet.ShowAllData


try it this way:

Worksheets("Check").Range("A1").AutoFilter Field:=14, Criteria1:="MISC"
Application.DisplayAlerts = False
ActiveSheet.Range("A2:A1000").SpecialCells(xlCellT ypeVisible).Delete
Application.DisplayAlerts = True
ActiveSheet.ShowAllData


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default COUNTIF VBA

On Friday, 4 March 2016 02:35:09 UTC-5, Claus Busch wrote:
Hi,

Am Thu, 3 Mar 2016 13:23:21 -0800 (PST) schrieb Merritt Ave:

Worksheets("Check").Range("A1").AutoFilter Field:=14, Criteria1:="MISC"
Application.DisplayAlerts = False
ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
Application.DisplayAlerts = True
ActiveSheet.ShowAllData


try it this way:

Worksheets("Check").Range("A1").AutoFilter Field:=14, Criteria1:="MISC"
Application.DisplayAlerts = False
ActiveSheet.Range("A2:A1000").SpecialCells(xlCellT ypeVisible).Delete
Application.DisplayAlerts = True
ActiveSheet.ShowAllData


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


Hi Claus - thanks for your response.
If I use your suggested method, it will give a VBA error when there is NOT an instance of the criteria search - NO CELLS WERE FOUND.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default COUNTIF VBA

Hi,

Am Fri, 4 Mar 2016 06:23:32 -0800 (PST) schrieb Merritt Ave:

If I use your suggested method, it will give a VBA error when there is NOT an instance of the criteria search - NO CELLS WERE FOUND.


for me it works fine. Do you have headers?

Try:

Dim myCrit As String
myCrit = "MISC"

If Application.CountIf(Range("N1:N1000"), myCrit) 0 Then
Worksheets("Check").Range("N1").AutoFilter Field:=1,
Criteria1:=myCrit
Application.DisplayAlerts = False

ActiveSheet.Range("N2:N1000").SpecialCells(xlCellT ypeVisible).EntireRow.Delete
Application.DisplayAlerts = True
ActiveSheet.AutoFilterMode = False
End If

or:

Const myCrit = "MISC"

If Application.CountIf(Range("N1:N1000"), myCrit) 0 Then
Worksheets("Check").Range("N1").AutoFilter Field:=1,
Criteria1:=myCrit
Application.DisplayAlerts = False

ActiveSheet.Range("N2:N1000").SpecialCells(xlCellT ypeVisible).EntireRow.Delete
Application.DisplayAlerts = True
ActiveSheet.AutoFilterMode = False
End If


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
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
COUNTIF help plaw Excel Worksheet Functions 3 January 21st 09 08:54 PM
How do I use a countif function according to two other countif fu. Kirsty Excel Worksheet Functions 2 February 20th 06 12:44 PM
edit this =COUNTIF(A1:F16,"*1-2*")+COUNTIF(A1:F16,"*2-1*") sctroy Excel Discussion (Misc queries) 2 September 25th 05 04:13 AM
COUNTIF or not to COUNTIF on a range in another sheet Ellie Excel Worksheet Functions 4 September 15th 05 10:06 PM
COUNTIF in one colum then COUNTIF in another...??? JonnieP Excel Worksheet Functions 3 February 22nd 05 03:55 PM


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

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

About Us

"It's about Microsoft Excel"