If Statement Otherwise VBA

heartyy

New Member
Joined
Feb 20, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I been trying to make this formula to work but I can't seem to make it work. The formula is on cell B1, =IF(AND(A1>200,A1<300),A1-200, otherwise do nothing). What I want for this to happen is if A1 is greater than 300 is to do nothing and the value that's already on B1 is not affected. If VBA is needed since it can not have a value in cell B1 then can you create me a VBA statement please. Much appreciated. Thank you.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If B1 contains a formula

tmp777.xlsm
AB
1150151
2250251
3350351
Sheet12
Cell Formulas
RangeFormula
B1:B3B1=A1+1


you can just incorporate it into the IF statement:

tmp777.xlsm
AB
1150151
225050
3350351
Sheet12
Cell Formulas
RangeFormula
B1:B3B1=IF(AND(A1>200,A1<300),A1-200, A1+1)
 
Upvote 0
This doesn't work because if cell A1 is less than 200 then cell B1 should be 0. Now, if cell A1 is 299 then the value in cell B1 should be 99 because it's over 200 but if cell A1 is greater then 300 then cell B1 should remain 99 and not change the value in that cell. Can this be done? If VBA is needed please show me the statment for it. Thank you.
 
Upvote 0
This doesn't work because if cell A1 is less than 200 then cell B1 should be 0. Now, if cell A1 is 299 then the value in cell B1 should be 99 because it's over 200 but if cell A1 is greater then 300 then cell B1 should remain 99 and not change the value in that cell. Can this be done? If VBA is needed please show me the statment for it. Thank you.

You have only provided a very small amount of information. Unless you can better define the formula, it will be difficult to help you.
Reading through your posts, here is my guess about what you want.

If A1 > 200 AND A1 < 300 then B1 = A1 - 200
If A1 <= 200 then B1 = 0
If A1 >= 300 then B1 = 99

That seems doable via a formula. No need for VBA
tmp777.xlsm
AB
100
21000
31990
42000
52011
62022
725050
829898
929999
1030099
1130199
12999999
Sheet12
Cell Formulas
RangeFormula
B1:B12B1=IF(A1<=200,0,IF(A1>=300,99,A1-200))

If I have guessed wrong, please explain with more detailed information.
 
Upvote 0
Solution
Sorry, I should have check it carefully. Your formula =IF(A1<=200,0,IF(A1>300,99,A1-200)) did not work for greater 300. The 99 in red it should be varable number meaning any number and not 99. Here's an example I created by month.

A B C
Jan. 285 85

Feb. 305 85

1. For January cell B is greater than 200 but less than 300 and cell C shows how much it's over 200.

2. For February cell B is greater than 300 therefore for February cell C number you use your last number that is greater than 200 but less than 300 for February cell C. In this case it was last month which is 85.

Bottomline is that you don't report any number that is greater than 300 for cell C. It's always greater than 200 but less than 300 for cell C so in this case we use the same number from January cell C which is 85 for February cell C.

I'm not very good explaining things but I hope you have a pretty good idea what I'm getting at. Thank you.

Oh, =IF(A1 <=200,0. This is good.
 
Upvote 0
I hope you have a pretty good idea what I'm getting at. Thank you.

I am sorry, but I do not. At all. Your most recent post has increased my confusion by 1000%. Perhaps someone else will come along to help. You might consider upgrading your abilty to post good examples by using this free tool which many here on the MrExcel board use:

 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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