?
Solved

Dividing to column A by column B and some cells in column B contains zeros.

Posted on 2013-01-02
12
Medium Priority
?
188 Views
Last Modified: 2013-01-02
How to do it with the simplest and shortest formula.

Kind regards,
EC
0
Comment
Question by:easycapital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 16

Expert Comment

by:Carol Chisholm
ID: 38737069
=IFERROR(A1/B1, "n/a")
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38737083
=IF(B1>0,A1/B1,"")
0
 
LVL 16

Expert Comment

by:Carol Chisholm
ID: 38737097
In case you have negative numbers
=IF(B1<>0,A1/B1, "")
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:easycapital
ID: 38737103
Formula should each row independently and then add each of those results. Eg. A1 / b1 + a2 / b2 + a3 b3 etc.
0
 
LVL 22

Expert Comment

by:Flyster
ID: 38737140
In C1 (or whatever you want your results in) you would put

=IF(B1>0,A1/B1,"")

In C2 you put =IF(B2>0,A2/B2,"") + C1 and then copy down.

Flyster
0
 

Author Comment

by:easycapital
ID: 38737176
Hi Flyster.
I need to write one formula which is short and simple which does what I am requesting. I tried the standard sumproduct formula but that divides all the rows and of course I get an error as some rows on column B are equal to zero.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38737265
Use this macro. It assumes that there are no headings.


Sub DivideAndSum()
Dim lngLastRow As Long
Dim lngIndex As Long

lngLastRow = Range("A65536").End(xlUp).Row
If Cells(1, 2).Value <> 0 Then
    Cells(1, 3).Value = Cells(1, 1).Value / Cells(1, 2).Value
Else
    Cells(1, 3).Value = 0
End If
For lngIndex = 2 To lngLastRow
    If Cells(lngIndex, 2).Value <> 0 Then
        Cells(lngIndex, 3).Value = Cells(lngIndex, 1).Value / Cells(lngIndex, 2).Value + Cells(lngIndex - 1, 3)
    Else
        Cells(lngIndex, 3).Value = Cells(lngIndex - 1, 3)
    End If
Next
End Sub

Open in new window

0
 
LVL 22

Assisted Solution

by:Flyster
Flyster earned 800 total points
ID: 38737284
If you're looking for that result in one cell, use this:

{=SUMPRODUCT(A1:A5,IF(B1:B5>0,1/(B1:B5),0))}

Adjust your range as needed. This must be entered as an array, so once you entered the formula, you have to hit ctrl+shift+enter.
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 1200 total points
ID: 38737449
Slight variation, also array entered

=SUM(IF(B1:B5,A1:A5/B1:B5))

regards, barry
0
 

Author Comment

by:easycapital
ID: 38737628
Hi, in Europe. So I will try tomorrow when in the office. Thanks, Jp
0
 
LVL 16

Expert Comment

by:Carol Chisholm
ID: 38737696
a demain
0
 

Author Closing Comment

by:easycapital
ID: 38739134
Barry, I went with your answer.

Carolchi, merci.

Thanks for the support!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question