Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA- Rows that has any data

Status
Not open for further replies.

Ramy27

Technical User
Apr 26, 2005
63
GB
I need to programatically count he number of ROWS that has any data in column A,C or D. (NOT no. of non-empty cells, but "non-empty" rows)

---------------------------------
Your help is much appreciated, R.
---------------------------------
 
so what have you tried ?

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
If it was one column i would have tried CountA(A:A) or something...but here i haven't a clue, sorry

---------------------------------
Your help is much appreciated, R.
---------------------------------
 
Hi,
Code:
    Set rng = Intersect(Union(Range("A:A"), Range("C:D")), ActiveSheet.UsedRange)
    With rng
      lFirstRow = .Row
      lLastRow = lFirstRow + .Rows.Count - 1
      i = 1
      For lRow = lFirstRow To lLastRow
        If Application.CountA( _
            Intersect(rng, _
                Union(Cells(lRow, "A"), _
                    Cells(lRow, "C"), _
                    Cells(lRow, "D")))) > 0 Then
            cnt = cnt + 1
        End If
        i = i + 1
      Next
    End With


Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
Hi, thanks for the code, but i'm getting the following error.
method intersect if '_Global' failed

---------------------------------
Your help is much appreciated, R.
---------------------------------
 
You are aware that this is not a helpdesk and you should be able to try and debug code a bit yourself...???

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
You may need
Code:
application.intersect(....)

application.union(....)

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top