Windows Vista Forums

Excel Range from variable

  1. #1


    OldDog Guest

    Excel Range from variable

    Hi,

    I am writing a script that will copy certain cells from on sheet to
    another. The problem I am having is that the cells I need can appear
    in diferent places in the original sheet.

    I can copy a range like this:

    ws1.Range("C3:C" & row).Copy(ws2.Range("A2"))

    However if I try to change the row and column to a variable it does
    not work.

    I have tried:

    ws1.Range(.Cells(rRow & "," & rCol).Cells(row & "," &
    rCol)).Copy(ws2.Range("B2"))

    And this;

    ws1.Range(rRow & "," & rCol & ":" & row & "," &
    rCol).Copy(ws2.Range("D2"))

    Any ideas?

      My System SpecsSystem Spec

  2.   


  3. #2


    John Guillory Guest

    Excel Range from variable

    To: OldDog
    Re: Excel Range from variable
    By: OldDog to microsoft.public.scripting.vbscript on Thu Apr 15 2010 11:36 am

    > ws1.Range("C3:C" & row).Copy(ws2.Range("A2"))
    > However if I try to change the row and column to a variable it does
    > not work.
    Try "Named Ranges", where you name the range of sells a meaningufl name....

    --- Synchronet 3.15a-Win32 NewsLink 1.92
    mlcgroup bbs - telnet://roachguts.com

      My System SpecsSystem Spec

  4. #3


    Brian Kelly Guest

    Re: Excel Range from variable

    OldDog wrote:

    > However if I try to change the row and column to a variable it does
    > not work.
    >
    > I have tried:
    >
    > ws1.Range(.Cells(rRow & "," & rCol).Cells(row & "," &
    > rCol)).Copy(ws2.Range("B2"))
    >
    > And this;
    >
    > ws1.Range(rRow & "," & rCol & ":" & row & "," &
    > rCol).Copy(ws2.Range("D2"))
    >
    > Any ideas?
    Use the cells property of the range object and use notation like cells(x,y)
    where x and y are integers e.g ws1.Range.cells(1,1) see
    http://www.anthony-vba.kefra.com/vba...Cells_Property
    for examples

    --
    Brian Kelly
    Home Page http://kellybk.com
    Species Race http://speciesrace.com



      My System SpecsSystem Spec


Excel Range from variable
Similar Threads
Thread Forum
RE: Assign variable value to excel cell VB Script
Excel / .Net: Extract a given Range into Picture or X(HT)ML? .NET General
How to get in a vbs script the sum of values of a Excel cells in a certain range? VB Script
Vista ASP.NET 2.0 Cannot open Excel File using Microsoft.Excel 12.0 COM object Software
How can I ensure that a variable is a built-in powershell variable? PowerShell