getting values of a range of data

R

ryu

I am trying to store the values of all the data in the worksheet but
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
 
S

Simon Lloyd

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

Here is my cod

Dim RangeValues As Varian

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

Thank you so much

--
Simon Lloy

Regards
Simon Lloy
'Microsoft Office Help' (http://www.thecodecage.com
 
B

Bob Umlas

the 2nd reference to Range("A2").End... refers to the active sheet, not
necessarily srcWorkbook...
Change to
srcWorkBook.Worksheets(sheetName).Range("A2",srcWorkBook.Worksheets(sheetName).Range("A2").End(xlDown).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" <[email protected]> wrote in messageI 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/showthread.php?t=122376>
 
A

arjen van...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top