+ Reply to Thread
Results 1 to 4 of 4

Count columns and rows from a defined range

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    Caribbean
    MS-Off Ver
    Excel 2007
    Posts
    5

    Count columns and rows from a defined range

    Hello,
    I would like to modify my code below to count columns and rows from a different range. Currently, the code below only reads from A1 of my data table. My data table starts at F7 with n columns and y rows. Each time I run the macro it does not recognise the range but only from A1.

    Could you help to modify this code to read for a defined range?

    Thanks in advance.


    Please Login or Register  to view this content.
    Dim iColumnCount As Integer
    Dim lRowCount As Long
    Dim iCol As Integer
    Dim dAverage As Double


    Worksheets(2).Activate
    ' Count number of columns and rows in use...
    iColumnCount = ActiveSheet.UsedRange.Columns.Count
    lRowCount = ActiveSheet.UsedRange.Rows.Count

    ' Cycle through each non-empty column...
    For iCol = 1 To iColumnCount
    ' Use the Average and StDev Excel functions to
    ' calculate values for each column...
    dAverage = WorksheetFunction.Average(Columns(iCol))

    ' Place results below existing data...
    Cells(lRowCount + 2, iCol).Value = dAverage

    Next iCol

    End Sub
    Please Login or Register  to view this content.
    Last edited by piercebrosnan; 06-22-2013 at 02:02 PM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Count columns and rows from a defined range

    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    06-19-2013
    Location
    Caribbean
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Count columns and rows from a defined range

    Thanks,
    I still get the column and row count as 0.
    Any suggestions?
    Thanks,

    PS: This was also posted on http://www.ozgrid.com/forum/showthre...goto=newpost**

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Count columns and rows from a defined range

    Please use code tags with your code.
    The code works for me. The only reason I can think it may not work may be you are using index numbering of your sheet. You should change to either the actual sheet name, or activesheet. Index no 2 may change.

    Please Login or Register  to view this content.
    Last edited by AB33; 06-22-2013 at 03:01 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1