Solved

Countif string is within cells in range

Posted on 2012-03-29
3
228 Views
Last Modified: 2012-04-02
Using VBA I am looking at finding how many cells within colum A range contain the following:-

Clear Move ;0

an example of a typical cell within the range is

2012-03-03; 21:18:55 ;PlayBack ?_? ;As008 ;Clear Move ;0 ;Positie ;-344 ; ; ; ;

What is the most elegant way (without next, for loops as the sheets are huge)

Thanks
0
Comment
Question by:simonwait
  • 2
3 Comments
 
LVL 1

Author Comment

by:simonwait
ID: 37782057
Oh actually its more complicated than that, sorry...hold the line....
0
 
LVL 1

Author Comment

by:simonwait
ID: 37782079
So if this is a typical few lines within the sheet:-

2012-03-21; 00:00:16 ;PlayBack 2_1 ;DT 1 ;Nieuwe storing ;65407459 ; ; ; ; ; ;
2012-03-21; 00:00:17 ;PlayBack ?_? ;DT 1 ;Clear Move ;0 ;Positie ;100 ; ; ; ;
2012-03-21; 00:00:18 ;PlayBack 2_1 ;DT 2 ;Nieuw Doel ;600 ;Positie, Delay,
2012-03-21; 00:00:18 ;PlayBack 2_1 ;DT 3 ;Nieuw Doel ;2000 ;Positie, Delay,
2012-03-21; 00:00:23 ;PlayBack ?_? ;DT 2 ;Clear Move ;0 ;Positie ;599 ; ; ; ;
2012-03-21; 00:00:23 ;PlayBack ?_? ;DT 3 ;Clear Move ;0 ;Positie ;2000 ; ; ; ;

I need to count the clear moves without a Nieuwe storing above them (where the DT number is also the same).

IE the second line should be counted because the line above is the sma e DT (DT1) and has a Niuewe storing string in it.  Lines 5 & 6 shouldnt be counted as their previous lines do not.

Thanks
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 37785267
I'm not understanding the description of the logic for which rows get counted.

<<I need to count the clear moves without a Nieuwe storing above...>>
<<second line should be counted because the line above is the same DT (DT1) and has a Niuewe storing string in it>>

Once we get the with and without straightened out: Do you need to test only the line immediately above the Clear Move, or all lines above it for the Nieuwe storing and DT?

The approach I suggest is to filter your data for cells containing Clear Move. You can then loop through the visible cells using SpecialCells(xlCellTypeVisible) and check for Nieuwe storing and DT in the row(s) above. This should be faster than looping through all the rows.

If you need to check all the rows above or Nieuwe storing and DT, it would be convenient to use Application.CountIf for that purpose. Doing so would be a lot easier if the order of fields were exactly as shown, because then you could use:
If Application.CountIf(myRange, ";DT 1 ;Nieuwe storing ;")>0 Then     'Found one
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now