Selection.Copy used in a variable.

R

Rick S.

How do I pass the variable "vData"?
'======
lRow = Range("A1").End(xlDown).Address
'MsgBox lRow 'for testing
vData = Range("A1:" & lRow).Copy
With Workbooks("TEMPLATE.xlsx")
.Worksheets.Add After:=.Worksheets(.Worksheets.Count)
vData.Paste 'Object required?
End With
'======
--
Regards

VBA.Noob.Confused
XP Pro
Office 2007
 
M

Mike H

Rick,

Maybe

Sub jj()
lRow = Range("A1").End(xlDown).Address
'MsgBox lRow 'for testing
vData = Range("A1:" & lRow).Copy
With ActiveWorkbook
.Worksheets.Add After:=.Worksheets(.Worksheets.Count)
ActiveSheet.Paste 'Object required?
End With
End Sub

Mike
 
M

Mike H

Rick,

I forgot to mention that I changed
With Workbooks("TEMPLATE.xlsx")
to
With ActiveWorkbook


For easier testing but it shouldn't make any difference when you change it
back

Mike
 
J

Jim Thomlinson

You do not copy cells to a variable and then pass the variable. Try something
more like this...

With Workbooks("TEMPLATE.xlsx")
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Copy _
.Worksheets.Add(After:=.Worksheets(.Worksheets.Count)).Range("A1")
end with
 
R

Rick S.

Activating the worksheet seemed to be one key, your bit of code also revealed
another key.

This is what I ended up with that works.
'======
lRow = Range("A1").End(xlDown).Address
Sheets(1).Range("A1:" & lRow).Copy
'need to get new workbook name as variable 01.24.08
With Workbooks("TEMPLATE.xlsx")
.Worksheets.Add After:=.Worksheets(.Worksheets.Count)
Workbooks("TEMPLATE.xlsx").Activate 'activate workbook
ActiveSheet.Paste 'paste data from workbook "ListA"
End With
ActiveWindow.SelectedSheets.Visible = False
Workbooks("ListA.xlsx").Close
'======

Thanks for your help!
--
Regards

VBA.Noob.Confused
XP Pro
Office 2007
 
R

Rick S.

I was afraid this was true.
Thanks for your help!

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007
 

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