VBA adding formula to cell

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
I am having problems...my code keeps erroring out. what am I doing wrong? Is the formula relative or do I have some areas to a absolute range that doesnt need? Please help :(



Sub addFormula()



Dim cell As Range


Range("AQ65536").End(xlUp).Select
Range(Selection, Selection.End(xlUp)).Offset(1, 1).Select



For Each cell In Selection
ActiveCell.Formular1c1 = "=IF(OR(K6>Impacts!$B$29,K6=Impacts!$B$29),IF(ISERROR(VLOOKUP _
(Mdata!A6,Subset!$A$339:$A$65536,1,FALSE)),"No","Yes"),"No")"
Next cell

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:

Sub addFormula()

Dim cell As Range
Dim Quote As String

Range("AQ65536").End(xlUp).Select
Range(Selection, Selection.End(xlUp)).Offset(1, 1).Select

Quote = Chr(34)

For Each cell In Selection

ActiveCell = "=IF(OR(K6>Impacts!$B$29,K6=Impacts!$B$29),IF(ISERROR(VLOOKUP(Mdata!A6,Subset!$A$339:$A$65536,1,FALSE))," & Quote & "No" & Quote & "," & Quote & "Yes" & Quote & ")," & Quote & "No" & Quote & ")"

Next cell

End Sub
 
Upvote 0
Ultimately I want it to say yes or no based on a couple of criterias. The formula works well when it is manually inserted into the spreadsheet but everytime I update the query the formula gets messed up. So I assume that I can just create a command that will update the workbook with the new data and then add the formula. But as you can tell, some cells need to be absolute and others relative. any thoughts?
 
Upvote 0
Hi arch


I just tried your code and it runs but nothing get populated in the field. i also added .formula to activecell just in case that did something, but no luck
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,803
Members
449,048
Latest member
greyangel23

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