Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign multiple cell's values to a variable


Need exact VBA code syntax to assign a workbook (to be closed) sheet's
cells J4 to J72 values to a variable called "ColJValues" to be assigned
to another sheet (to be opened later in the macro). The values are all
dates.

Once the other workbook is opened later in the macro, need the exact
syntax to assign the value in the above variable, "ColJValues", to it's
cells J4 to J72.

This would greatly help a learner. Thanks, mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=564020

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign multiple cell's values to a variable


Hello Mikeburg,

This macro should illustrate how to copy the range of one workbook to
the range of another workbook. The code to do this must reside in your
main workbook which isn't closed until you exit Excel. Also the code
assumes the required workbooks are already open. Remember this is to
illustrate the process. It isn't a tailored solution written for your
project. If you have any problems, it would be best to post the code
you have written for review.


Code:
--------------------

Sub CopyToWorkbook()

Dim ColJValues As Range
Dim Wkb1 As Workbook
Dim Wkb2 As Workbook
Dim Wkb1Name As String
Dim Wkb2Name As String
Dim Wks1Name As String
Dim Wks2Name As String

'Set the Workbook file names. This assume the Workbooks are already open
Wkb1Name = "My Test Book 1.xls"
Wkb2Name = "My Test Book 2.xls"

'Set the Worksheet names
Wks1Name = "Sheet1" '<<< Change to match your sheet's name in Workbook 1
Wks2Name = "Sheet1" '<<< Change to match your sheet's name in Workbook 2

'Copy values from Workbook 1 into the variable ColJValues
Set Wkb1 = Workbooks(Wkb1Name)
Set ColJValues = Wkb1.Worksheets(Wks1Name).Range("J4:J72")
Addx = ColJValues.Cells(1, 1).Address

'Copy the variable's data over to Workbook 2
Set Wkb2 = Workbooks(Wkb2Name)
ColJValues.Copy Destination:=Wkb2.Worksheets(Wks2Name).Range(Addx)

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=564020

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign multiple cell's values to a variable

I tried this code...I get an error message on this line:
Addx = ColJValues.Cells(1, 1).Address

'Object variable or With block variable not set'

Jodhi



Leith Ross wrote:
Hello Mikeburg,

This macro should illustrate how to copy the range of one workbook to
the range of another workbook. The code to do this must reside in your
main workbook which isn't closed until you exit Excel. Also the code
assumes the required workbooks are already open. Remember this is to
illustrate the process. It isn't a tailored solution written for your
project. If you have any problems, it would be best to post the code
you have written for review.


Code:
--------------------

Sub CopyToWorkbook()

Dim ColJValues As Range
Dim Wkb1 As Workbook
Dim Wkb2 As Workbook
Dim Wkb1Name As String
Dim Wkb2Name As String
Dim Wks1Name As String
Dim Wks2Name As String

'Set the Workbook file names. This assume the Workbooks are already open
Wkb1Name = "My Test Book 1.xls"
Wkb2Name = "My Test Book 2.xls"

'Set the Worksheet names
Wks1Name = "Sheet1" '<<< Change to match your sheet's name in Workbook 1
Wks2Name = "Sheet1" '<<< Change to match your sheet's name in Workbook 2

'Copy values from Workbook 1 into the variable ColJValues
Set Wkb1 = Workbooks(Wkb1Name)
Set ColJValues = Wkb1.Worksheets(Wks1Name).Range("J4:J72")
Addx = ColJValues.Cells(1, 1).Address

'Copy the variable's data over to Workbook 2
Set Wkb2 = Workbooks(Wkb2Name)
ColJValues.Copy Destination:=Wkb2.Worksheets(Wks2Name).Range(Addx)

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=564020


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
retrieving multiple corresponding values with variable rows/column soph Excel Worksheet Functions 4 September 15th 09 10:44 AM
how to sum all values of a variable that's repeated multiple times NC Excel Worksheet Functions 2 November 12th 08 02:03 PM
Lookup Multiple Values from a variable table size GCRDelphi Excel Worksheet Functions 1 August 5th 08 02:26 AM
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


All times are GMT +1. The time now is 04:39 AM.

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

About Us

"It's about Microsoft Excel"