Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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" wrote in message
oups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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" wrote in message
oups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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" wrote in message
oups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign value to a variable name Gnarlodious Excel Discussion (Misc queries) 2 August 20th 06 07:10 AM
Assign value to variable rroach Excel Discussion (Misc queries) 1 July 13th 05 05:24 AM
Variable VB to assign new sheet name Kevin M Excel Worksheet Functions 0 June 17th 05 12:15 AM
Assign a Date Variable within VBA Q John Excel Programming 9 December 21st 04 04:46 PM
assign variable Tim Excel Programming 10 October 1st 04 07:33 PM


All times are GMT +1. The time now is 11:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"