+ Reply to Thread
Results 1 to 5 of 5

How do I assign a variable to the curent work sheet?

  1. #1
    accelerator
    Guest

    How do I assign a variable to the curent work sheet?

    I'm writing a small macro that massages data between two sheets in one
    work book. What I'd like to do is something like this:

    Dim a, b as Worksheet

    a = <first worksheet>

    b = <second worksheet>

    b.cells(1,1) = a.cells(1,1)

    etc.


    However, the assignments fail.


  2. #2
    Gary Keramidas
    Guest

    Re: How do I assign a variable to the curent work sheet?

    try something like this

    Set A = Worksheets("Sheet1")
    Set B = Worksheets("Sheet2")

    B.Cells(1, 1).Value = A.Cells(1, 1).Value

    --


    Gary


    "accelerator" <[email protected]> wrote in message
    news:[email protected]...
    > I'm writing a small macro that massages data between two sheets in one
    > work book. What I'd like to do is something like this:
    >
    > Dim a, b as Worksheet
    >
    > a = <first worksheet>
    >
    > b = <second worksheet>
    >
    > b.cells(1,1) = a.cells(1,1)
    >
    > etc.
    >
    >
    > However, the assignments fail.
    >




  3. #3
    Gary Keramidas
    Guest

    Re: How do I assign a variable to the curent work sheet?

    try something like this:

    Dim A As Worksheet, B As Worksheet

    Sub copy_value()

    Set A = Worksheets("sheet1")
    Set B = Worksheets("Sheet2")

    B.Cells(1, 1).Value = A.Cells(1, 1).Value
    End Sub

    --


    Gary


    "accelerator" <[email protected]> wrote in message
    news:[email protected]...
    > I'm writing a small macro that massages data between two sheets in one
    > work book. What I'd like to do is something like this:
    >
    > Dim a, b as Worksheet
    >
    > a = <first worksheet>
    >
    > b = <second worksheet>
    >
    > b.cells(1,1) = a.cells(1,1)
    >
    > etc.
    >
    >
    > However, the assignments fail.
    >




  4. #4
    Norman Jones
    Guest

    Re: How do I assign a variable to the curent work sheet?

    Hi Accelerator,

    You need to use Set with object variables.

    The following worked for me:

    Sub Test()
    Dim a As Worksheet, b As Worksheet

    Set a = Sheets(1)

    Set b = Sheets(2)

    b.Cells(1, 1) = a.Cells(1, 1)

    End Sub


    BTW,

    > Dim a, b as Worksheet


    is equivalent to:


    Dim a as Variant , b as Worksheet


    ---
    Regards,
    Norman



    "accelerator" <[email protected]> wrote in message
    news:[email protected]...
    > I'm writing a small macro that massages data between two sheets in one
    > work book. What I'd like to do is something like this:
    >
    > Dim a, b as Worksheet
    >
    > a = <first worksheet>
    >
    > b = <second worksheet>
    >
    > b.cells(1,1) = a.cells(1,1)
    >
    > etc.
    >
    >
    > However, the assignments fail.
    >




  5. #5
    accelerator
    Guest

    Re: How do I assign a variable to the curent work sheet?

    When I try this:

    Dim a as Worksheet

    a = Sheet(1)

    I get the error message:

    Run-time error 438:

    Object doesn't support this property or method

    Oh I see! I have to use the "Set" statement.


+ 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