Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Excel macros VBA
i am creating a macro that transfer data from one workbook to another. i am getting a error please help. i have taken command button on workbook on b.xls which will run this.
 

 
Private Sub CommandButton1_Click()
 
Dim wkb1 As Workbook
Dim wknm As String
wknm = "d:\a.xlsx";
Set wkb1 = Workbooks.Open(wknm)
wkb1.Sheets("Sheet1").Range("A1:A8").Copy
 
ThisWorkbook.Sheets("Sheet1").Range("A1").Select
Selection.Paste
 
End Sub
Please help me find out what i am doing wrong
Thanks
aks619
Posted 22-Oct-12 22:50pm
aksh619297
Edited 22-Oct-12 22:58pm
v2
Comments
Zoltán Zörgő at 23-Oct-12 3:55am
   
You are getting error. Fine, and what error?
aksh619 at 23-Oct-12 3:57am
   
Application Defined or Object defined error !!
Zoltán Zörgő at 23-Oct-12 4:14am
   
And you have done step-by-step debugging, and you reached witch code row?
Buy as I see, you can not copy a range. Select it first, than copy, than select the target and than paste (See msdn).
aksh619 at 23-Oct-12 4:20am
   
now giving error select method of range class faild . i has put the whole code in Module .
Zoltán Zörgő at 23-Oct-12 4:26am
   
Workbook is opened?
Is there Sheet1?
Range is selected?
aksh619 at 23-Oct-12 4:28am
   
hey how can i go to different work book.... copy step is complete but
 
ThisWorkbook.Sheets("Sheet1").Range("A1").Select
Selection.Paste
 
not working
aksh619 at 23-Oct-12 4:26am
   
how to move to different workbook after copying from first

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is working fine for me:
Public Sub test()
Dim wb As Workbook
Set wb = Workbooks.Add
Workbooks(1).Activate
ActiveSheet.Range("A1").Value = 1
ActiveSheet.Range("A8").Value = 8
ActiveSheet.Range("A1:A8").Select
Selection.Copy
Workbooks(2).Activate
ActiveSheet.Range("A1").Select
ActiveSheet.Paste
End Sub
  Permalink  
Comments
aksh619 at 23-Oct-12 4:52am
   
Thanks Zoltan Zorgo, really appreciate you help .. but with one thing more how can i transfer entire coulmn to different workbook worksheet ..
Zoltán Zörgő at 23-Oct-12 12:32pm
   
Use the "A:A" format for one column or "A:C" for many. I suppose you can only select consequent columns.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 330
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 23 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100