View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default get number of rows

Hi

The macro below uses two approaches to calculate number of rows. r1
calculate last row in used range. r2 calculate last row with data in column
A.

Sub aaa()
r1 = Sheets("Sheet1").Range("A1").SpecialCells(xlCellTy peLastCell).Row
r2 = Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
If r1 < r2 Then
msg = MsgBox("Sheet1 has " & r1 & " number and Sheet 2 has " & r2 & "
number." _
& vbLf & vbLf & "Do you wish to proceed?", vbExclamation + vbYesNo,
"Error")
If msg = vbNo Then Exit Sub
End If
End Sub

Regards,
Per

"Rachel" skrev i meddelelsen
...
HI,

Anyone who can help?

I have 2 worksheets. I want to compare the number of used rows of both
worksheet, If the number does not match, I want it to display a ERROR MSG
"Sheet1 has (blank) number and Sheet2 has (blank) number. Do you wish to
proceed?"

Any help will be highly appreciated. THANKS!