Nested If Statement using VBA (practice)

nycintern

New Member
Joined
Jun 18, 2015
Messages
6
Hi.

I am trying to automate a process that can be laborous. So let's say on cell C2:C10, I used vlookup from a data file to pull out a % which ranges from (0%-5%). On the corresponding column D, I would like to have a rating, which is taken out from a rating scale. So my congested IF statement on Column D looks like this: =IF(C2<0.75%,"1",IF(C2<1.5%,"2",IF(C2>1.501%,"3","N/A")))

Which says the value of C2 is between 0 and .75% then we geit it a 1, if its between .75% and 1.5% its a 2, and so on. How can I put this in VBA, and if I could, should I? I am able to get what I need with the Ifstatement.

Please advise,
Intern
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Well I suppose you could just have excel enter the formula on your behalf.

Code:
Sub Test()

Sheets("Sheet1").Activate
Range("D2").Formula = "=IF(C2<0.75%,""1"",IF(C2<1.5%,""2"",IF(C2>1.501%,""3"",""N/A"")))"
Range("D2").Copy Range("D3:D10")

End Sub

That's not too different from saving the formula though and having it available for later to copy/paste when you pull new data. Are you just trying to make the formula more dynamic in some way? (variable number of if criteria or something?)
 
Upvote 0
Hi. Thank you. I'm trying to learn and understand VBA. Possibly by reading the codes (like the one you posted) and understanding how it all works. I honestly don't know what VBA can do for me and how it can make my life easier b/c i'm not familiar with it and it's beyond my imagination.
 
Upvote 0
It can do a lot - quite a bit more than I originally imagined in fact. I have quite a few reports where the work is literally reduced to:

-Open file
-Hit a button
-Skim results for anything interesting

You have the right idea though, start where the workload is most tedious or repetitive.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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