Results 1 to 2 of 2

Thread: Copying Ranges in Excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    Montreal, Quebec
    Posts
    400

    Copying Ranges in Excel

    I need to copy one column in a worksheet to 4 different columns in another worksheet. I'm using a For... Next Loop because the single column is updated with new values. In the first loop, the data is sent to the first col in the other sheet; in the second loop, the data is sent to the next col in the other sheet, etc. I tried defining my columns as a variable as shown below but VB doesn't like the second reference to the worksheet in last line of the code. Any ideas how to correct this?
    Code:
        For col = 4 To 7
            xlBook.Worksheets("input").Cells(2, 3).Value = Form1.txtSWProd1(col - 4).Text
            xlBook.Worksheets("output").Range("C1:C58").Copy xlBook.Worksheets("marginal").Range("3", col:"60",col)
        Next col

  2. #2
    WorkHorse
    Guest
    The parameters being passed to Range aren't correct. I'd use Offset to move to the new columns.

    VB Code:
    1. ' Copy range from worksheet "output" to column number "col" in worksheet "marginal"
    2.     xlBook.Worksheets("output").Range("C1:C58").Copy _
    3.         xlBook.Worksheets("marginal").Range("A1").Offset(0, col)

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