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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

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?
 

Forum statistics

Threads
1,172,221
Messages
5,879,770
Members
433,455
Latest member
d3kk3r

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