I'll try to make this as short as possible. I need to rewrite the formulas of a number of cells depending on what worksheet they're located in.
Dim sFrmla As String
Dim rSomerange As Range
Let sFrmla = "=OFFSET(INDIRECT(INDIRECT(" & Chr(34) & "E" & Chr(34) & "&ROW()));0;"
Let rSomerange.Formula = sFrmla & wsSheet.Name & "_ZERO_SCALE)"
Let rSomerange.Formula = sFrmla & wsSheet.Name & "_FULL_SCALE)"
Let rSomerange.Formula = sFrmla & wsSheet.Name & "_PRCSUNIT)"
This crashes at the second line (Zero_scale) and gives me a runtime error 1004. I have already made sure that the range itself exists and is writable.
Funny part is that the same code but without the formula string works just fine.
Let rSomerange.Formula = wsSheet.Name & "_ZERO_SCALE)"
Any ideas?
Let
keyword. It's odd in this case. ,
or semicolon ;
), you should always use comma ,
with Range.Formula
. If you'd like to use your regional separator (semicolon ;
in your case), use Range.FormulaLocal
instead. So, you should use:
sFrmla = "=OFFSET(INDIRECT(INDIRECT(" & Chr(34) & "E" & Chr(34) & "&ROW())),0,"
rSomerange.Formula = sFrmla & wsSheet.Name & "_ZERO_SCALE)"
or
sFrmla = "=OFFSET(INDIRECT(INDIRECT(" & Chr(34) & "E" & Chr(34) & "&ROW()));0;"
rSomerange.FormulaLocal = sFrmla & wsSheet.Name & "_ZERO_SCALE)"
or shorter version:
sFrmla = "=OFFSET(INDIRECT(INDIRECT(""E""&ROW())),0,"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.