+ Reply to Thread
Results 1 to 2 of 2

Working with ranges

Hybrid View

okaderli Working with ranges 03-26-2007, 03:22 PM
Leith Ross Hello Okaderli, Here is a... 03-26-2007, 10:12 PM
  1. #1
    Registered User
    Join Date
    03-26-2007
    Posts
    1

    Working with ranges

    I want make special statistical tests using Excel.
    Without using ranges it is very difficult to make certain calculations.
    The tests will be about statistical distributions that are not included in Excel Analysis Toolpaks.
    I want to learn about using ranges in Excel.
    I have read about using ranges in formulas.

    For example;
    the sample may consist of two variables each having different number of records; weight (30 rows), height (43 rows).

    I want to create a variable length range, but I don't know how.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Okaderli,

    Here is a code example that assigns either the weight range or the height range to a range variable named "Rng". The weight range is "A1:A30" and the height range is "B1:B43". Both ranges are located on worksheet "Sheet1".

    Examples:
      Dim Rng As Range
       'Define Rng' to be equal to the weight range
        Set Rng = Worksheets("Sheet1").Range("A1:A30")
       'Define Rng to be equal to the height range
        Set Rng = Worksheets("Sheet1").Range("B1:B43")
    These next examples assume there are header labels in row 1 and "A1" is labeled "Weight" and "B1" is labeled "Height". Both Names have been entered with their defined ranges of "A1:A30" and "B1:B43".

    Examples with named ranges:
      Dim Rng As Range
       'The label "Weight" refers to  a named range
        Set Rng = Worksheets("Sheet1").Range(Weight)
       'The label "Height" refers to a named range
        Set Rng = Worksheets("Sheet1").Range("B1:B43")
        
        'Note: if the code is placed within the General Declarations code
        'or in the Worksheet event code modules of Sheet1 then the code
        'can be written as follows:  
        'Set Rng = Range("A1:A30")  or Set Rng = Range(Weight)
    Example of finding a Range's length:
      Dim LastRowA As Long
      Dim LastRowB As Long
      Dim RngA As Range
      Dim RngB As Range
    
        With Worksheets("Sheet1")
          LastRowA = .cells(.Rows.Count, "A").End(xlUp).Row
          LastRowB = .Cells(.Rows.Count, "B").End(xlUp).Row
         'RngA = Weight
          Set RngA = Range("A1:A" & LastRowA)
         'RngB = Height
          Set RngB = Range("B1:B" & LastRowB)
        End With
    Sincerely,
    Leith Ross

+ 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