[VBA] .formula = "=" & variable - Error 1004

Uehara

New Member
Joined
Nov 30, 2012
Messages
2
Hello,

I'm trying to use the .formula function in VBA but I don't know how to use it with a variable following the "=" character...

Here's my code:


Code:
Dim sheetlist As String
Dim i As Integer

i = 2

While Range("B" & i).Value <> ""

   sheetlist = Range("B" & i).Value
   Range("C" & i).Formula = "=" & sheetlist & " '!$D$3

   i = i + 1

Wend

I got a "error 1004 : Application-defined or object-defined error".

Thanks
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Almost got it, just put a ' after the = sign so it looks like this:


Code:
Dim sheetlist As String
Dim i As Integer
i = 2
While Range("B" & i).Value <> ""
   sheetlist = Range("B" & i).Value
   Range("C" & i) = "='" & sheetlist & "'!$D$3"
   i = i + 1
Wend
 
Upvote 0
Almost got it, just put a ' after the = sign so it looks like this:


Code:
Dim sheetlist As String
Dim i As Integer
i = 2
While Range("B" & i).Value <> ""
   sheetlist = Range("B" & i).Value
   Range("C" & i) = "='" & sheetlist & "'!$D$3"
   i = i + 1
Wend

Thank you bjurney, it works.

Got stuck 2 hours on this :mad:
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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