Pulling formulas from cells into VBA for modification

bmckenna

New Member
Joined
Oct 15, 2009
Messages
33
Hey all,

This is my first post here, and hopefully the first of many more.

Anyways, I have about 40 or so cells that need their cell formula altered, so I pull in the formula, which works, modify it, which works, but when I try to output it to the sheet, no go. I tried dim as string/variant/double, but nothing. I keep getting the 1004 Application-Defined or Object-Defined error. Here's the code:

Sub EditFormula()
Dim x As String
For i = 7 To 49
With ThisWorkbook.Sheets("INTERFACE2")
x = .Cells(i, 2).Formula
.Cells(i, 3) = "=iferror(" + CStr(x) + ", rr)"
End With
Next i
End Sub

Thanks!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I assume that your formula "iferror" is a Function;

Try this:

Sub EditFormula()
Dim x As String
For i = 7 To 49
With ThisWorkbook.Sheets("INTERFACE2")
x = .Cells(i, 2).Formula
.Cells(i, 3) = "=iferror(" & CStr(x) & ", rr)"
End With
Next i
End Sub


I guess you meant this formula:

"IF(ISERROR......" If so then use the following

Sub EditFormula()
Dim x As String
For i = 7 To 49
With ThisWorkbook.Sheets("INTERFACE2")
x = .Cells(i, 2).Formula
.Cells(i, 3) = "=IF(ISERROR(" & CStr(x) & "), rr)"
End With
Next i
End Sub
 
Last edited:
Upvote 0
No go, same error, I did this below:

Sub EditFormula()
Dim x As String
For i = 7 To 49
With ThisWorkbook.Sheets("INTERFACE2")
x = .Cells(i, 2).Formula
y = "=iferror(" & CStr(x) & ", rr)"
Stop
.Cells(i, 3) = y
End With
Next i
End Sub

I look at my locals window when it hits the Stop, and my y is equal to:

: y : "=iferror(=INDIRECT("Data!A"&B$6), rr)" : Variant/String
 
Upvote 0
What is rr - a named range?

You'll need to lose the = before INDIRECT

Code:
y = "=iferror(" & Right(x, Len(x) - 1) & ", rr)"
 
Upvote 0
Right you are Peter, any ideas how to pull in that formula without that equals sign before the indirect? Also, the rr will eventually be "", but I will find and replace that later, since VBA already uses the " for itself.
 
Last edited:
Upvote 0
Try this:

Sub EditFormula()
Dim x As String
For i = 7 To 49
With ThisWorkbook.Sheets("INTERFACE2")
x = .Cells(i, 2).Formula
x = Mid(x, 2)
y = "=iferror(" & CStr(x) & ", ""rr"")"
Stop
.Cells(i, 3) = y
End With
Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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