Formulas in VBA help needed

dwpfreak

New Member
Joined
Feb 22, 2008
Messages
26
Hi all you helpful people.

I have this code but I wish to add more formulas to it applying to different columns.

1 Is there any limit to the amount of formulae in a code?
2 How do I write in the next formula?
3 Can i get this string of code to run all the time or when opening or saving?

I tried myself but it debugged.

With Range("C50:C500")
.Formula = "=IF(AND(A50=1,B50=1),""yes"",""no"")"
.Value = .Value
With Range("d50:d500")
.Formula = "=IF(A50=""Yes"",""yes"",""no"")"
.Value = .Value
With Range("e50:e500")
.Formula = "=IF(d50=""yes"",f50=1)"
.Value = .Value

End With
'
End Sub

I want to add the formula in red but it says compile error.
Any help greatfully appreciated

Dwpfreak
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You need to end each of your Withs

Code:
Sub test()
With Range("C50:C500")
    .Formula = "=IF(AND(A50=1,B50=1),""yes"",""no"")"
    .Value = .Value
End With
With Range("d50:d500")
    .Formula = "=IF(A50=""Yes"",""yes"",""no"")"
    .Value = .Value
End With
End Sub

Your last formula doesn't make sense though.
 

dwpfreak

New Member
Joined
Feb 22, 2008
Messages
26
thanks for that, and i corrected the formula.

Do you know how to make this stringof code run all the time or on opening and closing?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,087
Messages
5,599,654
Members
414,325
Latest member
kfg1287

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
Top