Help - Formula applied to column A1:a4000 using VBA

dwpfreak

New Member
Joined
Feb 22, 2008
Messages
32
Hi all,

I have tool I use to manage staff performance and I would like to use vba to run formulas if possible.

for example column A50 to A5000 will hold the value 1, and then
column b50 to b5000 holds the value 1,

then column GA50 to GA5000 will return the Value 1.

so A50 and B50 = 2 then GA50 = 1 or the Value "YES".

I would like the VBA code to apply to that range 50-5000 on the press of a button. The button already exists I just need the code to paste into it.

The normal formula i would apply is =if(a50:b50,1,2) OR =IF(A50+B50,2,"yes")

But as this is one of many of lots of formulas applied to the range 50-5000 the memory size is jacked up. Hence slowing spreadsheet the speed.

I have used F2 function to succesful place one formula into a code, but found i had to F2 and Enter on every cell I wanted.

Is there a short cut?

Hope that made sense.

thanks

The Freak

PS - I know that this places the formula into the cell, but i intend to copy values back to another cell (say c50:c5000) and clear the formulas in ga50:ga5000) so they are not retained anywhere except in the VBA code.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
    With Range("G50:G500")
        .Formula = "=IF(A50+B50,2,""yes"")"
        .Value = .Value
    End With
 
Upvote 0
Wow thank you, adds all the way down but..

when i change value a50 to 0, it still when run shows 2 in g50, can it show 0 or No instead?

also can i change it to return the text "yes" not 2.

but brillant stuff though.
 
Upvote 0
I thought you didn't want formulae as it slowed the spreadsheet down.

If you want formulae, remove the .Value = .Value line.

As for the other bit, modify the formula.
 
Upvote 0
hi, thank you for replying again.

Yes amended, great stuff, I amended it to

With Range("c50:c5000")
.Formula = "=IF(A50+B50,2,""YES"")"
.Value = .Value
End With
'
End Sub

if it is not 2 it shows "false", i tried adding ,""No"") after the yes section but it debugged.

Also sorry to be a pain but I want it to return "No" if it doesn't equal 2, I tried using <> but it again debugged.

Sorry to be such a pain on Sunday.

thanks



 
Upvote 0
Do you mean

Code:
    With Range("C50:C500")
        .Formula = "=IF(AND(A50=1,B50=1),""yes"",""no"")"
        .Value = .Value
    End With
 
Upvote 0
great, thankyou, i am slowly learning vba and formulas but its clear i have a way to go..

thanks for your help
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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