Solved

Countif string is within cells in range

Posted on 2012-03-29
3
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

719 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