Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to write an excel macro that does a simple calculation using values in existing cells and outputs a value. I basically want to write a formula that takes column a and column b and does the following operation (b/(a+b)) and puts the answer in column c. This needs to be done for rows 1 through 4. I do not have a lot of programming experience so Im not exactly sure where to begin. If someone could let me know which commands and or processes i need to write this macro.

Dim i As Integer
i = 1

Do While Cells(i, 1).Value <> ""
    Cells(i, 3).Value = Cells(i, 1).Value / (Cells(i, 2).Value + Cells(i, 1).Value)
    i = i + 1
Loop
share|improve this question
    
what have you tried so far? –  simoco Apr 1 at 19:02
    
Ive tried doing a loop through but I don't know if this is right. Dim i As Integer i = 1 Do While Cells(i, 1).Value <> "" Cells(i, 3).Value = Cells(i, 1).Value / (Cells(i, 2).Value + Cells(i, 1).Value) i = i + 1 Loop –  reddells Apr 1 at 19:03
1  
it's very good! but what problems do you have with this code? –  simoco Apr 1 at 19:05
1  
Have you enabled the developer tab and entered the Visual Basic Editor and placed your code in subroutine within a new module? –  Raystafarian Apr 1 at 19:14
    
Code as currently written is doing (a/a+b). Otherwise, this looks like it should work. What seems to be the problem? –  David Zemens Apr 1 at 19:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.