ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   getting values of a range of data (https://www.excelbanter.com/excel-programming/432014-getting-values-range-data.html)

ryu[_6_]

getting values of a range of data
 

I am trying to store the values of all the data in the worksheet but I
keep getting the Run-time error '1004'. Please help.

Here is my code

Dim RangeValues As Variant

RangeValues =
srcWorkBook.Worksheets(sheetName).Range("A2",Range ("A2").End(xlDown).End(xlToRight)).Value

Thank you so much!


--
ryu
------------------------------------------------------------------------
ryu's Profile: http://www.thecodecage.com/forumz/member.php?userid=602
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=122376


Simon Lloyd[_1220_]

getting values of a range of data
 

Ryu, what is the entire range you are trying to encompass?ryu;441175 Wrote:
I am trying to store the values of all the data in the worksheet but I
keep getting the Run-time error '1004'. Please help.

Here is my code

Dim RangeValues As Variant

RangeValues =
srcWorkBook.Worksheets(sheetName).Range("A2",Range ("A2").End(xlDown).End(xlToRight)).Value

Thank you so much!



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=122376


Bob Umlas[_3_]

getting values of a range of data
 
the 2nd reference to Range("A2").End... refers to the active sheet, not
necessarily srcWorkbook...
Change to
srcWorkBook.Worksheets(sheetName).Range("A2",srcWo rkBook.Worksheets(sheetName).Range("A2").End(xlDow n).End(xlToRight)).ValueorWith srcWorkBook.Worksheets(sheetName) RangeValues = .Range("A2",.Range("A2").End(xlDown).End(xlToRight )).Valueend With(note the "." before each range)HTHBob UmlasExcel MVP"ryu" wrote in ... I am trying to store the values of all the data in the worksheet but I keep getting the Run-time error '1004'. Please help. Here is my code Dim RangeValues As Variant RangeValues =srcWorkBook.Worksheets(sheetName).Range("A2",Ran ge("A2").End(xlDown).End(xlToRight)).Value Thank you so much! -- ryu ------------------------------------------------------------------------ ryu's Profile: http://www.thecodecage.com/forumz/member.php?userid=602 View this thread:http://www.thecodecage.com/forumz/showthread.php?t=122376


arjen van...

getting values of a range of data
 
using a with / end with structure can shorten it a bit:

With srcWorkbook.Worksheets(sheetname)
RangeValues = .Range(.Range("A2"), _
.Range("A2").End(xlDown).End(xlToRight)).Value
End With


All times are GMT +1. The time now is 07:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com