Array to range with values that look like formula

gousssam

New Member
Joined
Jul 1, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello. I'm having a problem where excel will throw a 1004 error "application-defined or object-defined error".

The issue is that I have an array of values with strings that look like "=?DAFqwr".

As a minimal example of this:

Sub testArr()

dim arr(1 to 1, 1 to 1) as variant

arr(1,1) = "=x2j?1"
range("A1").value2 = arr(1,1) ' error occurs here

end sub

Does anyone know of any workarounds for this?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hello. I'm having a problem where excel will throw a 1004 error "application-defined or object-defined error".

The issue is that I have an array of values with strings that look like "=?DAFqwr".

As a minimal example of this:

Sub testArr()

dim arr(1 to 1, 1 to 1) as variant

arr(1,1) = "=x2j?1"
range("A1").value2 = arr(1,1) ' error occurs here

end sub

Does anyone know of any workarounds for this?
Sorry, that code works, the issue is when the string starts with =? e.g. "=?anyletters"
So this will throw the error as described:

Sub testArr()

dim arr(1 to 1, 1 to 1) as variant

arr(1,1) = "=?x2j?1"
range("A1").value2 = arr(1,1) ' error occurs here

end sub
 
Upvote 0
@gousssam Does this help?

VBA Code:
Sub testArr()

Dim arr(1 To 1, 1 To 1) As Variant

arr(1, 1) = "=?x2j?1"
With Range("A1")
.NumberFormat = "@"
.Value2 = arr(1, 1) ' error occurs here
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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