Add if row contains a string in excel [closed] - excel

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Without the use of macros or anything fancy, is it possible to write an excel formula that would add up Col-1 rows that correspond to Col-2 rows having the string 'st'?
+----+-------+-------+
+ # + Col-1 + Col-2 +
+----+ ------+-------+
+ 1 + 1 + an st +
+ 2 + 2 + f st +
+ 3 + 1 + st fr +
+ 4 + 1 + bd bd +
+----+-------+-------+
So in this example, it should add up rows 1,2 and 3 and return 1+2+1 = 4

There is a way. Use this: =SUMPRODUCT(ISNUMBER(FIND("st",B1:B4))*A1:A4)

Why do we not just use:
=SUMIF(B1:B4,"*st*",A1:A4)

I'd introduce a third column. The values of the third column will be the one of the first if the second contains the string, 0 otherwise.
Summing up the values in the third column will return the result you want.
If you don't like to display or print the column you introduce you should hide it.

Assuming the first row is in Row 1, starting at column a, you can add another column to the right which checks for each, using this formula:
=IF(ISNUMBER(SEARCH("st", C1)), B1, 0)
That should return 1, 2, 1, 0 respectively for your rows.
Sum that column for the total.

Related

I want to make a loop checking for pairs VBA [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a project involving checking for pairs in a column. I´m a beginner so I tried
If a = b Then
Par = Par + 1
End If
If a = c Then
Par = Par + 1
End If
If a = d Then
Par = Par + 1
End If
etc etc but if I want this to work I´ll have to repeat this code 36 times...
Is there an easy loop for this?
Here is a simple way that might meet your needs.
Imagine a simple table in range A1:B5
A B
1 aa aa
2 cc bb
3 ee cc
4 gg dd
5 hh ee
Here we have three pairs aa & aa, cc & cc, ee & ee.
This formula will count the number of pairs:
=SUMPRODUCT(COUNTIF(A1:A5,B1:B5)) // = 3

Sum numbers in a cell that appear as a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Example: string in cell
1 1 1 1 (total should be 4)
0.5 0.5 (total should be 1)
0.125 0.125 (total should be 0.250)
0.125 0.0625 8 1 (total should be 9.1875)
First use Text To Columns to get the individual numbers into individual cells. Then use the =SUM() function across the individual numbers.
EDIT#1
If you need a VBA solution, then consider:
Public Function AddCell(s As String) As Variant
ary = Split(Trim(s), " ")
AddCell = 0
For i = LBound(ary) To UBound(ary)
AddCell = AddCell + ary(i)
Next i
End Function

Select/Highlight Columns in Excel 2010 Based on Their Addresses [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a column in Excel which contains the addresses of the cells that need to be selected and then highlighted. Please find below a snapshot:
Col# Row# Corresponding Address
8 1 $H$1
9 2 $I$2
10 3 $J$3
10 4 $J$4
9 5 $I$5
10 6 $J$6
10 7 $J$7
10 8 $J$8
11 9 $K$9
12 10 $L$10
12 11 $L$11
11 12 $K$12
As an example, I need to select cell $H$1 and highlight it.
I would like to perform this task automatically for a large matrix. What would the vba code be for this task?
Any help is highly appreciated
You would need to loop through the Corresponding Address column and set, (assuming that you want the cell colour changed in order to highlight it) the Interior.Colour to a RGB value:
Dim x As Worksheet, y As Worksheet
Dim CtrA As Long
Set x = Worksheets("SheetName1")
Set y = Worksheets("SheetName2")
For CtrA = 2 To x.Rows.Count
y.Range(x.Range("C" & CtrA)).Interior.Color = RGB(0, 255, 0)
Next
where x is a reference to the sheet containing the table in your question, and y is a reference to the sheet that contains the cells you want to highlight.

How can I SUMIFS where criteria is a set of numbers from a column? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have an Excel file that looks like this:
ZONES Count Area 1 = (SUM OF ZONE COUNT)
------------------------------------------------------------------------------
1 100 1
2 50 2
3 110 5
4 90 7
5 40
6 10
7 0
8 80
What I need to do is make (SUM OF ZONE COUNT) say 190 since 100+40+50+0 = 190. I've tried:
=SUMIFS(B3:B10, A3:A10, C3)
And it will return 100. When I try:
=SUMIFS(B3:B10, A3:A10, "="&C3:C6)
It returns 0.
I need to set the criteria to be a range instead of an individual cell.
Is this possible?
Try this version
=SUMPRODUCT(SUMIFS(B3:B10,A3:A10,C3:C6))
because the criteria range is four cells the SUMIFS function will return an "array" of four values - SUMPRODUCT is used to sum those four values
You can also use SUM but the formula needs to be "array entered", i.e.
=SUM(SUMIFS(B3:B10,A3:A10,C3:C6))
confirm with CTRL+SHIFT+ENTER

Spreadsheet Formula (math) [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This is purely a math question!
I simply can't get my head around this formula. It is so simple, but I can't get it to work in general.
I have 2 columns of numbers.
Columns A+B is the full number of apples (100%).
Column A: is the number of apples that I have eaten.
Column B: is the number of apples that are left.
I need column C to be the percentage of apples that are left out of the full number.
For example.
A B C
0 3 100%
5 0 0%
2 2 50%
Can anybody wrap their heads around this?
Total = A + B
Left out apples = B
Percentage of left out apples = (B / Total) * 100
Consequently, here's the formula:
Column C = ((Column B) / (Column A + Column B) * 100)
Here's what you should type-in in Excel:
=(B1/(A1+B1))*100
A = No. of apples eaten, B = No. of apples left . A+B = total no of apples. So Total no. of apples left out of the full amount are (A+B)-A/100.

Resources