Consulting

Results 1 to 4 of 4

Thread: Copy and paste of multiple ranges

  1. #1
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    2
    Location

    Copy and paste of multiple ranges

    Hello,
    this is my first post here, great forum.
    I have spent some time searching the forum for a solution to my problem, but I could't find any. I had some old Access related experience with VBA.

    I have the following problem. I'm trying to copy to a separate excel file multiple ranges defined in a reference table:
    eg.
    FILE1 | A1:G3
    FILE2 | A1:G1,A5:G7
    FILE3 | a1:g1,a8:g9

    etc.

    My code looks like:
    [vba]
    '' Loop on reference table...

    Worksheets("Report").Range(C.Offset(0, 1)).Copy
    ...
    Set MiXL = GetObject("", "Excel.Application")
    Set WB = MiXL.Workbooks.Add
    With WB.ActiveSheet.Cells("1", "A")
    .PasteSpecial xlPasteValues
    .PasteSpecial xlPasteFormats
    Application.CutCopyMode = False
    End With
    [/vba]
    When I open the generated files, the range intervals are not respected and FILE 2 (for instance) contains also the interval A2:G5 - that should not be in the specified range.
    I believe that the problem lives in the way I define the intervals. I have also attached a sample excel file with the full macro and some sample data.

    Thanks for your time

    Luciano

  2. #2
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    That's weird. It appears that Excel simple makes a mistake when copying the range to the other workbook.

  3. #3
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    2
    Location

    RE: Copy and paste of multiple ranges

    I think I have found a solution but is this an Excel 2003 bug?

    Thanks
    Luciano

  4. #4
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    I don't know. I tested the range before writing on the new workbook, I even switched range intervals and it was correct. But, when it tries to write on the new workbook, it makes a mistake.

    This can be solved splitting the range information in the cell where you define the range area to write, of course, but I tought this weird.

Posting Permissions

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