+ Reply to Thread
Results 1 to 10 of 10

Problem in copying cells from another workbook.

  1. #1
    Registered User
    Join Date
    06-16-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    29

    Problem in copying cells from another workbook.

    Hi all,

    Kindly help me with the following error.

    I am trying to copy one value from sh1 and paste it in a common sheet (sh2) for every value in sh2.I am repeating the process for all the value in sh1. Sh1,sh2,sh3 are defined as worksheets and open.


    "k = sh1.Range("A1", sh1.Range("A1").End(xlDown)).Rows.Count

    l = sh2.Range("J1", sh2.Range("J1").End(xlDown)).Rows.Count


    For i = 2 To k

    For j = 2 To l




    sh1.Cells(i, 1).Copy Destination:=sh3.Cells(x, 1).Paste 'won,k,i
    sh2.Cells(j, 1).Copy Destination:=sh3.Cells(x, 2).Paste 'month,j,l
    x = x + 1

    Next j

    Next i"


    But it is throwing a Runtime error:object defined or application defined error.

    Kindly help me to find out whats wrong.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Problem in copying cells from another workbook.

    One thing - x is not defined. Is there more too the code? Where are you're other variable defined?

  3. #3
    Registered User
    Join Date
    06-16-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    29

    Re: Problem in copying cells from another workbook.

    I have defined

    "
    Dim sh1 As Worksheet
    Dim sh2 As Worksheet
    Dim sh3 As Worksheet
    Dim x As Integer, i As Integer, j As Integer

    Set sh1 = Workbooks(Master).Sheets("Sheet1")
    Set sh2 = ThisWorkbook.Sheets("Sheet2")
    Set sh3 = ThisWorkbook.Sheets("Sheet1")
    "

    Should i define anything else?
    John H.davis

  4. #4
    Registered User
    Join Date
    06-16-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    29

    Re: Problem in copying cells from another workbook.

    I have defined k and l also as integer

  5. #5
    Registered User
    Join Date
    06-16-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    29

    Re: Problem in copying cells from another workbook.

    I am getting "object doesnot support this property or method " after defining values....

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Problem in copying cells from another workbook.

    Try defining x, i, & k as long. BTW x needs a beginning value outside of the loops.

  7. #7
    Registered User
    Join Date
    06-16-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    29

    Re: Problem in copying cells from another workbook.

    The complete code looks like this

    " Dim sh1 As Worksheet
    Dim sh2 As Worksheet
    Dim sh3 As Worksheet
    Dim x As Long, i As Long, j As Integer, k As Long, l As Integer

    Set sh1 = Workbooks(Master).Sheets("Sheet1")
    Set sh2 = ThisWorkbook.Sheets("Sheet2")
    Set sh3 = ThisWorkbook.Sheets("Sheet1")

    k = sh1.Range("A1", sh1.Range("A1").End(xlDown)).Rows.Count

    l = sh2.Range("J1", sh2.Range("J1").End(xlDown)).Rows.Count

    x = 2

    For i = 2 To k

    For j = 2 To l

    sh1.Cells(i, 1).Copy Destination:=sh3.Cells(x, 1).Paste
    sh2.Cells(j, 1).Copy Destination:=sh3.Cells(x, 2).Paste
    x = x + 1

    Next j

    Next i"


    Complete code looks like this and i get an error at


    " sh1.Cells(i, 1).Copy Destination:=sh3.Cells(x, 1).Paste
    sh2.Cells(j, 1).Copy Destination:=sh3.Cells(x, 2).Paste "

    Error: Object doesnt support this property or method
    . Kindly help....

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Problem in copying cells from another workbook.

    OK, I think this

    Please Login or Register  to view this content.
    Should be

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-16-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    29

    Re: Problem in copying cells from another workbook.

    Even thats not working can you give me someother code to copy from sh1(another workbook) to sh3.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Problem in copying cells from another workbook.

    Maybe:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with copying worksheet with Macro into a new workbook
    By Coems in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2015, 07:22 AM
  2. Copying formula between workbook problem
    By gjjh25 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-01-2013, 08:56 AM
  3. Problem copying a cell from one workbook to another.
    By Turtleman10 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2013, 02:46 PM
  4. Problem copying multiple tabs to a new workbook
    By bleat in forum Excel General
    Replies: 1
    Last Post: 05-23-2012, 06:09 AM
  5. Problem copying worksheet to another workbook
    By jmartin53 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-01-2012, 08:16 PM
  6. problem copying workbook
    By Rich Kniatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-14-2006, 07:42 PM
  7. [SOLVED] Problem copying cells to another workbook
    By Sergio Calleja in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2005, 06:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1