Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
ben ben is offline
external usenet poster
 
Posts: 232
Default Areas, rows and colums

dtrudell,

A couple of things. First usedrange.rows.count and usedrange.columns.count
can return total rows and columns count
Second
selection.areas.count
DOES NOT APPLY TO THE AREAS. That count how many non-continuous selections
you have.
the following code should select every non-blank, non-formula cell in your
worksheet
Cells.Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
This code will select non-blank, formula cells
Cells.Select
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
and this code will select EVERY NONBLANK cell in your workbook

Cells.Select
Set r1 = Selection.SpecialCells(xlCellTypeConstants, 23)
Set r2 = Selection.SpecialCells(xlCellTypeFormulas, 23)
Union(r1, r2).Select

once you have those select your selection.areas.count should display total
areas

--
When you lose your mind, you free your life.


"dtrudell" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Areas, rows and colums

Sub MultiAreas()
Range("A1,B2,C3,D4,E5,E1,D2,B4,A5").Select
MsgBox Selection.Areas.Count
End Sub

If you only select a single area, the count will always be 1. In your code
you don't show anything that selects prior to your areas.count test.

--
Regards,
Tom Ogilvy



"dtrudell" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Areas, rows and colums

The statement
ActiveCell.SpecialCells(xlLastCell).Select
will select the last affected cell in a sheet.

You can then use
ActiveCell.Row
ActiveCell.Column

to retrieve the row and column number of that cell to see if if meets your
criteria.

HTH...Glenn Ray



"dtrudell" wrote:

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
rows and colums lizfox Excel Discussion (Misc queries) 2 November 20th 09 07:04 PM
Inserting Rows in multiple areas jlclyde Excel Discussion (Misc queries) 1 January 24th 08 08:18 PM
How do change rows to colums AND columns to rows Colleen A Excel Discussion (Misc queries) 7 December 30th 05 12:40 AM
Print few rows with many colums so that rows wrap on printed pages usfgradstudent31 Excel Discussion (Misc queries) 1 October 20th 05 02:39 PM
How do I name the colums and rows? Cin3 New Users to Excel 5 January 5th 05 11:09 PM


All times are GMT +1. The time now is 04:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"