Solved

Countif string is within cells in range

Posted on 2012-03-29
3
230 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

776 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