Formulas in VBA help needed

dwpfreak

New Member
Joined
Feb 22, 2008
Messages
32
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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.
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

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