Results 1 to 5 of 5

Thread: [RESOLVED] Stranger Problem with copy data from sheet to another

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Resolved [RESOLVED] Stranger Problem with copy data from sheet to another

    I tried this code to copy the data from the sheet1 to "bills" sheet
    it must starts copy in the third row in the "bills" sheet. but it starts form another row and every time I delet the data in "bills" sheet it starts from the new row. Take a look to the example I uploaded. How to fix this problem?

    Code:
    Dim myRange1 As Range, myRange2 As Range, myRange3 As Range, myRange4 As Range
    Dim myRange5 As Range, myRange6 As Range, myRange7 As Range, myRange8 As Range
    Dim myRange9 As Range, myRange10 As Range, myRange11 As Range, myRange12 As Range
    Dim j As Integer
       
        Set myRange1 = Sheets(1).Range("A24:A1000")
        Set myRange2 = Sheets(1).Range("B24:B100")
        Set myRange3 = Sheets(1).Range("C24:A1000")
        Set myRange4 = Sheets(1).Range("D24:B100")
        Set myRange5 = Sheets(1).Range("E24:A1000")
        Set myRange6 = Sheets(1).Range("F24:B100")
        Set myRange7 = Sheets(1).Range("G24:A1000")
        Set myRange8 = Sheets(1).Range("H24:B100")
        Set myRange9 = Sheets(1).Range("I24:A1000")
        Set myRange10 = Sheets(1).Range("J24:B100")
        Set myRange11 = Sheets(1).Range("K24:A1000")
        Set myRange12 = Sheets(1).Range("L24:B100")
        
        j = Sheets("Bills").UsedRange.Rows.Count + 1 + Sheets("Bills").UsedRange.Row
       
        myRange1.Copy Sheets("Bills").Range("a" & j)
        myRange2.Copy Sheets("Bills").Range("b" & j)
        myRange3.Copy Sheets("Bills").Range("c" & j)
        myRange4.Copy Sheets("Bills").Range("d" & j)
        myRange5.Copy Sheets("Bills").Range("e" & j)
        myRange6.Copy Sheets("Bills").Range("f" & j)
        myRange7.Copy Sheets("Bills").Range("g" & j)
        myRange8.Copy Sheets("Bills").Range("h" & j)
        myRange9.Copy Sheets("Bills").Range("i" & j)
        myRange10.Copy Sheets("Bills").Range("j" & j)
        myRange11.Copy Sheets("Bills").Range("k" & j)
        myRange12.Copy Sheets("Bills").Range("l" & j)
    Attached Files Attached Files
    Last edited by nader; Feb 5th, 2008 at 09:54 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Stranger Problem with copy data from sheet to another

    used range is not reset when cell content is deleted, so if you delete the content of the last 2 rows, you would get 2 additional blank rows, if you delete (or cut) 2 rows i believe then the usedrange would be correct

    also you don't need to set the ranges then copy, you can just copy the range
    vb Code:
    1. Sheets(1).Range("A24:A1000").Copy Sheets("Bills").Range("a" & j)
    make sure to set j first
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: Stranger Problem with copy data from sheet to another

    Quote Originally Posted by westconn1
    used range is not reset when cell content is deleted, so if you delete the content of the last 2 rows, you would get 2 additional blank rows, if you delete (or cut) 2 rows i believe then the usedrange would be correct
    I couldn't understand ....

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Stranger Problem with copy data from sheet to another

    even if you delete the values from some rows of cells, they are still used
    at least until the workbook is saved and closed
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: Stranger Problem with copy data from sheet to another

    I used this code
    vb Code:
    1. Cells.clear
    and it success with me.

    Thank you for help

Posting Permissions

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



Click Here to Expand Forum to Full Width