Solved

Countif string is within cells in range

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
excel file 5 47
Conditional format Excel Cell 3 18
Excel VBA - format a Shape same as a Cell 7 23
Rearrange Macro 7 18
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
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 Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

757 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

20 Experts available now in Live!

Get 1:1 Help Now