Range transfer

alee001

Board Regular
Joined
Sep 9, 2014
Messages
154
Office Version
  1. 2010
Platform
  1. Windows
How to transfer the range to other range/location after calculation? Thanks.
VBA Code:
Sub sample()
Dim rng As Range
Dim r As Range
Dim i As Long
Dim arr() As Variant
Set rng = Application.Range("B2:D11")
ReDim arr(rng.Count)
For Each r In rng
    i = i + 1
    arr(i) = r + 1
Next
Cells(6, 7).Resize(10, 3) = arr() 'how to transfer?
Set rng = Nothing
Set arr = Nothing
End Sub
 
Yes, we can see that and that is why we have been offering you simple alternative codes that do transfer the data. :)

If you really must use an array then you can do it like this

VBA Code:
Sub sample2()
  Dim arr As Variant

  arr = Range("B2:D11").Value
  Cells(6, 7).Resize(UBound(arr), UBound(arr, 2)).Value = arr
End Sub

But I need each cells value in arr +1 then transfer to Cells(6, 7).Resize(UBound(arr), UBound(arr, 2)).Value as answer...?
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Have you actually tried any of the solutions that have been posted to see if they in fact do what you are asking for? Or are you just deciding they don't work because you are unfamiliar with what has been proposed?
 
Upvote 0
Have you actually tried any of the solutions that have been posted to see if they in fact do what you are asking for? Or are you just deciding they don't work because you are unfamiliar with what has been proposed?
I know how to transfer range value but no idea how to transfer calculated answer by array.
 
Upvote 0
:oops: I apologise. I, & I think Rick too, have not taken enough notice of what your code was trying to do.
However, I still don't see the need to individually adjust the 2-dimensional range values and turn them into a 1-dimensional array only to then split them out again into a 2-dimensional range.

VBA Code:
Sub sample2()
  Cells(6, 7).Resize(10, 3).Value = Evaluate("B2:D11+1")
End Sub

If you really do want to transfer the values to an array, perhaps to do some other things first before returning them to the worksheet, then you could more easily use a 2-dimensional array the same size & shape as the original and destination ranges.

VBA Code:
Sub sample3()
  Dim arr As Variant
  
  arr = Evaluate("B2:D11+1")
  Cells(6, 7).Resize(UBound(arr), UBound(arr, 2)).Value = arr
End Sub
 
Upvote 0
Solution
:oops: I apologise. I, & I think Rick too, have not taken enough notice of what your code was trying to do.
However, I still don't see the need to individually adjust the 2-dimensional range values and turn them into a 1-dimensional array only to then split them out again into a 2-dimensional range.

VBA Code:
Sub sample2()
  Cells(6, 7).Resize(10, 3).Value = Evaluate("B2:D11+1")
End Sub

If you really do want to transfer the values to an array, perhaps to do some other things first before returning them to the worksheet, then you could more easily use a 2-dimensional array the same size & shape as the original and destination ranges.

VBA Code:
Sub sample3()
  Dim arr As Variant
 
  arr = Evaluate("B2:D11+1")
  Cells(6, 7).Resize(UBound(arr), UBound(arr, 2)).Value = arr
End Sub
Yes, Thank you for you let me know the Evaluate's function and I learn more.
 
Upvote 0
You're welcome. Sorry it took me so long to realise what you were trying to do. :(
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,709
Members
449,118
Latest member
MichealRed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top