Output cell value (not formula) from VBA to Excel

Formula11

Active Member
Joined
Mar 1, 2005
Messages
468
Office Version
  1. 365
Platform
  1. Windows
I have arrays that I want to write from VBA to Excel. The Microsoft website gives advice and gives code similar to what's shown below (http://support.microsoft.com/default.aspx?scid=kb;en-us;306022).

My question relates to the following line:

DataArray(r, 11) = "=RC[+14]"

What this does is input a formula in column 11 from the same row but 14 columns to the right. * The cell contents in Excel have a formula in there, but what I need is a value. *

Any assistance would be appreciated.



Sub Update()
Dim DataArray(1 To 1000, 1 To 20) As Variant
Dim r As Integer
For r = 1 To 1000
DataArray(r, 1) = "ORD" & Format(r, "0000")
DataArray(r, 2) = Rnd() * 1000
DataArray(r, 3) = DataArray(r, 2) * 0.7
DataArray(r, 11) = "=RC[+14]"
Next
Sheets("Sheet1").Range("A1").Resize(1000, 20).Value = DataArray
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I have arrays that I want to write from VBA to Excel. The Microsoft website gives advice and gives code similar to what's shown below (http://support.microsoft.com/default.aspx?scid=kb;en-us;306022).

My question relates to the following line:

DataArray(r, 11) = "=RC[+14]"

What this does is input a formula in column 11 from the same row but 14 columns to the right. * The cell contents in Excel have a formula in there, but what I need is a value. *

Any assistance would be appreciated.



Sub Update()
Dim DataArray(1 To 1000, 1 To 20) As Variant
Dim r As Integer
For r = 1 To 1000
DataArray(r, 1) = "ORD" & Format(r, "0000")
DataArray(r, 2) = Rnd() * 1000
DataArray(r, 3) = DataArray(r, 2) * 0.7
DataArray(r, 11) = "=RC[+14]"
Next
Sheets("Sheet1").Range("A1").Resize(1000, 20).Value = DataArray
End Sub

Definitely this is just a stab at it, try:

Replacing "=RC[+14]"

With Cells(ActiveCell.Row, ActiveCell.Column + 14).Value
 
Upvote 0
John, thanks for responding.

Unfortunately that command didn't work, what it does it erase all entries.
 
Upvote 0
The requirement is not entirely clear to me. Do you just want the value from column Y in column K?

If so, try this alternate code in a copy of your workbook.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Update()<br>    <SPAN style="color:#00007F">Dim</SPAN> DataArray(1 <SPAN style="color:#00007F">To</SPAN> 1000, 1 <SPAN style="color:#00007F">To</SPAN> 20) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> r <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br>    <br>    <SPAN style="color:#00007F">For</SPAN> r = 1 <SPAN style="color:#00007F">To</SPAN> 1000<br>        DataArray(r, 1) = "ORD" & Format(r, "0000")<br>        DataArray(r, 2) = Rnd() * 1000<br>        DataArray(r, 3) = DataArray(r, 2) * 0.7<br>        <SPAN style="color:#007F00">'DataArray(r, 11) = "=RC[+14]"</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN><br>        <SPAN style="color:#007F00">'Sheets("Sheet1").Range("A1").Resize(1000, 20).Value = DataArray</SPAN><br>        <SPAN style="color:#00007F">With</SPAN> Sheets("Sheet1")<br>            .Range("A1").Resize(1000, 20).Value = DataArray<br>            .Range("K1:K1000").Value = .Range("Y1:Y1000").Value<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>


If this is not what you want please try to clarify further.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

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