|
-
May 24th, 2002, 12:33 PM
#1
Thread Starter
Hyperactive Member
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
-
May 24th, 2002, 10:19 PM
#2
The parameters being passed to Range aren't correct. I'd use Offset to move to the new columns.
VB Code:
' Copy range from worksheet "output" to column number "col" in worksheet "marginal"
xlBook.Worksheets("output").Range("C1:C58").Copy _
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|