Click here to Skip to main content
11,719,185 members (81,596 online)
Rate this: bad
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)
End Sub
Please help me find out what i am doing wrong
Posted 22-Oct-12 21:50pm
Edited 22-Oct-12 21:58pm
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


not working
aksh619 at 23-Oct-12 4:26am
how to move to different workbook after copying from first

1 solution

Rate this: bad
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
ActiveSheet.Range("A1").Value = 1
ActiveSheet.Range("A8").Value = 8
End Sub
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 Sergey Alexandrovich Kryukov 1,734
1 OriginalGriff 690
2 Maciej Los 569
3 Richard MacCutchan 540
4 F-ES Sitecore 510

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 23 Oct 2012
Copyright © CodeProject, 1999-2015
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