[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Countif string is within cells in range

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
simonwait
Asked:
simonwait
  • 2
1 Solution
 
simonwaitAuthor Commented:
Oh actually its more complicated than that, sorry...hold the line....
0
 
simonwaitAuthor Commented:
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
 
byundtCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now