View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
dtrudell dtrudell is offline
external usenet poster
 
Posts: 1
Default Areas, rows and colums

I am trying to write a code to help analyze data and need to determine the
number of areas, rows and columns in each worksheet that is accessed.
Based on help searches, I have written the following crude code but it does
not work for all worksheets. Of great concern is that the
"selection.Areas.count" does not give me anything more than "one area". The
Rows and Columns count property gives various answers depending on the layout
of the worksheet. Does anyone have any suggestions?

Code:
Sub Rows_Cols()
' procedure counts the number of rows and columns
Dim nAreaCnt As Integer 'Determines if the sheet is formated properly for
analysis
Dim nRowCnt As Integer 'Stores the number of Rows in the sheet
Dim nCowCnt As Integer 'Stores the number of Columns in the sheet

nAreaCnt = Selection.Areas.Count
MsgBox "Number of Areas " & nAreaCnt
If nAreaCnt = 1 Then
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
nColCnt = Selection.Columns.Count
nRowCnt = Selection.Rows.Count
MsgBox "Number of Rows " & nRowCnt
MsgBox "Number of columns " & nColCnt
Else
MsgBox "Worksheet has empty rows or columns. Please fill sheet"
End If

End Sub