Counting Rows

  • Thread starter Thread starter Dave Coz
  • Start date Start date
D

Dave Coz

Hello,
I am trying to do the following:
1. Count populated Rows using VB
2. If the # of populated rows is less than 2 post a message box dsiplaying
the count
3. If the # of populated rows is greater than 3, continue on with the rest
of the macro.

Anything you can do to hlep is greatly appreciated.
 
This will look at the last populated cell in the desired row.

Sub countrowsincolA()
mc = 2 '"a"
x = Cells(Rows.Count, mc).End(xlUp).Row
If x < 2 Then
MsgBox "Only " & x
Else
'goon
MsgBox "oh boy"
End If

End Sub
 
You mean the number of used rows in a single column?

dim myNum as long
mynum = application.counta(worksheets("Somesheetnamehere").range("a:a"))
if mynum < 2 then
msgbox mynum
'exit sub '???
else
rest of macro here
end if

I figured you meant greater than or equal to 3. If you didn't, what happens at
3?
 
Hi,

You might try

Dim x As Long
x = WorksheetFunction.CountA(Range("A:A"))
If x < 2 Then
MsgBox x & " rows have data."
End If

if you want to exit the routine if x<2 then add a line after MsgBox the reads
Exit Sub

If you just want the message box then

Dim x As Long
x = WorksheetFunction.CountA(Range("A:A"))
If x < 2 Then MsgBox x & " rows have data."

these assume the column A is the one you are checking.
 
Back
Top