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. #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

  3. #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
create Excel spreadsheet without loading Excel
Greetings, I have a script which uses CreateObject("Excel.Application") to create a spreadsheet. This works fine on my machine since I have Excel...
VB Script
RE: Assign variable value to excel cell
Hi, the code works. Are you sure that variable "strabc" has a value? I try this and it works: --- Dim Xcl Dim strabc
VB Script
Excel / .Net: Extract a given Range into Picture or X(HT)ML?
Hello there, Is there any -reliable- way to extract certain, given ranges in excel files into either a picture (each) or into proper xhtml? I am...
.NET General
How to get in a vbs script the sum of values of a Excel cells in a certain range?
Assume I want to get the sum of values of all cells from the range "H6:H18" from an Excel Worksheet. How can I do this within vbs script? ...
VB Script
How to view Excel document without Microsoft Office Excel installe
I bought new PC of Vista Home edition. I can't view a Excel made document that was sent to me by friend because my new visa PC has no Microsoft...
Vista General
Vista ASP.NET 2.0 Cannot open Excel File using Microsoft.Excel 12.0 COM object
I am using an ASP.NET 2.0 web application using the Interop assembly pointing to the Microsoft.Excel 12.0 COM to open and write to a spreadsheet. ...
Software
How can I ensure that a variable is a built-in powershell variable?
I have a question regarding variables. Is there a way to ensure that retrieved variable such as *Preference variables are indeed a built-in...
PowerShell