Zulake
Zulake

Reputation: 149

VB.NET Copying Excel Range

I have used the code below to copy an excel range.

oSheetDestination.Range("A1:A10").Value = oSheetSource.Range("A1:A10").Value

But I would like to copy the range based on the cell number location using something like this:

oSheetDestination.Range("1,1:1,10").Value = oSheetSource.Range("1,1:1,10").Value

Any ideas how I can do that?

Thanks,

Upvotes: 0

Views: 1366

Answers (2)

CristiC777
CristiC777

Reputation: 481

try:

Friend Shared Sub TestRangeCells(myworksheet As Worksheet)
Dim myrange As Range = myworksheet.Range(worksheet.Cells(1, 1), myworksheet.Cells(5, 10))
MessageBox.Show(myrange.Address)
End Sub

Upvotes: 1

Degustaf
Degustaf

Reputation: 2670

I think what you are looking for is the Cells property. From there, your best bet is to do a resize

oSheetDestination.Cells(1,1).resize(1,10).Value = _
     oSheetSource.Cells(1,1).resize(1,10).Value

Upvotes: 2

Related Questions