add the same number until it exceeds another and return that number vba

Sotos13

New Member
Joined
Mar 8, 2019
Messages
42
Hello everyone

I'm new in vba and try to figure out some stuff. I have a two columns in excel and i want to compare each number , for example A1 with B1. A2 with B2 etc..
If A1 is smaller than B1 return in cell C1 the B1. If not add the number in B1 as many times until it is bigger than A1.

1810
24525
3144

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
in line 1 the answer is 8<10 = 10, line 2 the answer is 25+25 = 50,line 3 the answer is 4+4+4+4 = 16.

So i started like this but i cant figure out how to proceed..
Dim qAnswer As Integer
qAnswer = 2
If Cells(qAnswer, 1).Value < Cells(qAnswer, 2).Value And Not IsEmpty(Cells(qAnswer, 1).Value) Then
Cells(qAnswer, 3) = Cells(qAnswer, 2).Value
Else

Any suggestions?
Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
i will probably post some more within the next days because it's not that easy for me now in the beginning. i hope you'll see them.
thanks again
 
Upvote 0
Sounds like you have headers above your values. So far you've said your values start from A1.

There's an easy fix for this: Set the Rng to start from cells(2,1)
 
Upvote 0
If anyone is interested in a solution with formulas, maybe


A
B
C
1
8​
10​
10​
2
45​
25​
50​
3
14​
8​
16​
4
34​
2​
36​
5
16​
12​
24​
6
25​
16​
32​
7
22​
10​
30​
8
36​
4​
40​
9
6​
12​
12​
10
48​
8​
56​
11
50​
2​
52​
12
10​
8​
16​
13
20​
10​
30​
14
11​
6​
12​
15
48​
10​
50​
16
16​
5​
20​
17
17​
8​
24​
18
7​
18​
18​

Formula in C1 copied down
=IF(B1>A1,B1,CEILING(A1+1,B1))

M.
 
Upvote 0
thank you Marcello..It works also like this!!!
but for some numbers it returns a higher number for example 50 and 2 and returns 52 not 50
 
Last edited:
Upvote 0
thank you Marcello..It works also like this!!!
but for some numbers it returns a higher number for example 50 and 2 and returns 52 not 50

If A1 is smaller than B1 return in cell C1 the B1. If not add the number in B1 as many times until it is bigger than A1.

I thought you wanted the result always greater than column A, not greater or equal.

If column C equal to column A is acceptable, then change the formula to C1 for simply ..
=IF(B1>A1,B1,CEILING(A1,B1))
and copy down

M.
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,063
Members
449,206
Latest member
Healthydogs

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