reduce cell value by increment until condition is met

Mr vdC

New Member
Joined
Aug 11, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi, I have driven myself "loopy" over something quite basic:

"A1" is a variable integer that feeds into an equation that yields "b2" as the result. "B3" is the copied value of "b2" at the start, so "b3" = "b2". "B3" does not get refreshed if "B2" changes.

The code I am trying to compile will cover:
A1 can only be between 0 and 1000.
reduce the value of "a1" by incremental steps of 1 until b2 <> b3, then print the last "a1" value in "a1" where "b3"= "b2"


every time i try this i get a plethora of errors or end up in an infinity loop :(
any help would be greatly appreciated.
many thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
my code is here:


Sub inc()

Dim n As Integer
n = 1
o = Range("B2").Value
p = Range("B3").Value
Do Until o <> p
Range("a1") = Range("a1") - n
n = n + 1
Loop

End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: reduce cell value by increment until condition is met
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
appologies to all. I have posted here and on excelforum. Thats it.
 
Upvote 0
I have resolved it

Sub incTP()

Do While Range("b2").Value = Range("b3").Value

Range("a1").Value = Range("a1").Value - 1

Loop

Range("a1").Value = Range("a1").Value + 1

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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