Sum numbers that contain a letter in the cell - vba

I'm trying to sum a3:b21 but in these cells they will either have a c or s as the first character in the cell, Some cells might just be the letter itself. the values can be in the range of $1 all the up to $99999.
I have tried a few different formulas but none are adding the cells. Some of the formulas I have tried are
=SUM(IF((LEFT(A3:B20,1))=C3,(--RIGHT((IF(A3:B20="",0,A3:B20)),7)),0))
=IF(ISNUMBER(A3:B20),M3,VALUE(RIGHT(M3,SEARCH(" ",A3:B20)-1)))
=SUMIF(A3:B20,M2,A3:B20)
=SUMIF(A3:B19, "s*")
For the time being while I try and figure out a formula that works I have m2 for the letter s and m3 for the letter c, for testing different formulas.
Sample cell:

If you can add a column and sum from that try this, it acts like a replace() function. Will remove c and s. You can nest other substitutes() to remove other characters as necessary
=substitute(substitute("a3","c",""),"s","")+0
Then copy for other cells

This worked for me.
=SUMPRODUCT(--(LEFT(A1:A3,1)="c"),IFERROR(--RIGHT(A1:A3,LEN(A1:A3)-1),0))
CSE-entered.

Related

Spreadsheet - Conditional formatting cells based on other cells

Conditional formatting a cell is simple enough. It's also simple enough to conditionally format a single cell based on another single cell. What I'm not sure about is doing it for many cells in such a way that I don't have to format each individual cell. For example:
Suppose the cells in column A either have a string, or are blank. How can I set conditional formatting on the cells in column B, such that the formatting is only applied if the A column cell on the same row (ie, the adjacent cell) is blank?
So far, I've been working around this issue by wrapping the formulas of the cells in B with IF(ISBLANK(A1),0,"FORMULA"), then applying conditional formatting to the B cells based on whether the cell values equal 0. Is there a better solution than this?
Yes, in my opinion. For LibreOffice Calc select ColumnB, Format > Conditional Formatting..., choose Formula is and enter:
A1=""
then a style of your choice and OK.
You might want to reduce the upper limit of Cell Range.
Apply the condition to Column B:
And use the following formula:
=NOT(ISBLANK($A1))
This will result in something like this:
=NOT(ISBLANK(OFFSET($A$1, ROW()-1, 0, 1, 1)))

Conditional formatting based on formula addressing current row in LibreOffice Calc

I have a column of cells in LibreOffice Calc with conditional formatting to apply a style to those cells.
The conditional formatting is programmed to format the cell if the following formula is true:
AND(B106=0,C106=0)
The trick is that instead of always evaluating this formula for row #106, I would like to evaluate the formula for the current row.
For example, in cell A1, I would like the conditional formula to be
AND(B1=0,C1=0)
And in cell A2, I would like the conditional formula to be
AND(B2=0,C2=0)
What I'm looking for is to program the entire column with a conditional formula like
AND(BCURRENTROW()=0,CCURRENTROW()=0)
but obviously that syntax is incorrect.
How can I accomplish this?
A conditional formatting based on a formula has two settings that determines where and how it applies.
First is the Cell Range to which it applies to. If this is
Range : A1:A1048576
then it applies to the whole column A.
Second is the formula itself. Precisely whether cell ranges in that formula are relative or absolute or mixed. As in all other formulas, a relative cell reference is A1 for example. A absolute cell reference is $A$1 for example. And mixed cell references could be $A1, where column A is absolute but row is relative, or A$1, where column is relative but row 1 is absolute.
So a conditional formatting applied to range A1:A1048576 and having formula AND($B1=0,$C1=0) should fulfilling your requirement. As you see the formula always gets columns B and C (absolute) but gets the row in which it is actually calculated (relative).
Example:
If you want to paint all row with a color when the column "B" CONTAINS a value, for example "XXX" you can do this:
Format-> Conditional Formatting (Add)
We select "formula" and we put:
SEARCH("XXX";$B2)>=0
We apply the style "Good" (To view selected rows in green)
And we select the matrix in we want actuate (important!), by example :
A2:H109
Now we see all the rows where the column B contains "XXX" in green.
enjoy !

How to count occurrence of each sentence in Excel in this specific case?

The challenge here is the sentence is not split by cell. They are in the same column, but they might appear in the same cell. One sentence per line.
I need to count the occurrence of each sentence, for example, occurrence of "The cat is pink" is 2 and occurrence of "The dog is green" is 1.
I can also do Access 2016 if needed.
(Assuming you can split multi-sentence cells into multiple cells)
1) Split the cells with multiple sentences, you should be able to adapt this code to do this.
2) Make a copy of the column (elsewhere on the same sheet or in another sheet -- used column B in the same sheet),
3) Remove duplicate values for the copied column
4) Next to the column use the following array formula:
{=SUM(LEN(A$1:A$5)-LEN(SUBSTITUTE(A$1:A$5,B1,"")))/LEN(B1)}
(press <CTRL><SHIFT><ENTER> when entering an array formula)
sort column A --> a-z then
add a header to column A (to use in subtotals)
then from the Data tab, use "subtotals" using "count" as the function
=COUNTIF(A:A,"*Cat is Yellow*")
The same formula can be applied for all the rows.

How can I use Conditional formatting formula in the filter in the Gsheets to select 2 or more columns where cells that are not empty in both?

so I have ABCDE columns and I want to see rows of the cells that are not empty in the C as well as D column. how do I do this? I know I can have one column do that but that way it would exclude the information in the other column.
Let me know if this doesnt make sense. I'll try to explain with an example
I am a little confused by your question as to whether you are trying to use Conditional Formatting or to create a filter.
If you are trying to use Conditional Formatting:
It sounds like you are trying to highlight a row if there is not a blank cell in column C and not a blank cell in column D of that row.
Create a Conditional Formatting rule with the following:
Apply to Range A1:E1000 <-- (or however many rows of data you have)
Format cells if... SELECT "Custom formula is"
=or(NOT(isblank($C1)),NOT(isblank($D1)))
Formatting style Pick a color to highlight the row
This rule will highlight columns A-E for each row that has data in both column C and column D.

Setting FormulaArray to Formula skips every other row and column

A very fast way to enter formulas is like this:
Range("E5:H10").Formula = "=A1"
The column and row references adjust, so that for example the formula this code enters in cell H10 is "=D6".
However, that doesn't work for array formulas:
Range("E5:H10").FormulaArray = "=A1"
That puts the array formula {=A1} in each of the cells; no adjustments for rows or columns.
Of course you can loop through all the cells and enter a unique array formula in each one, but that isn't fast.
So I tried this:
Range("E5:H10").Formula = "=A1"
Range("E5:H10").FormulaArray = Range("E5:H10").Formula
But the results were surprising -- the references skip every other row and every other column; for example:
-- The formula in F5 is {=C1} instead of the expected {=B1}, and
-- The formula in D6 is {=A3} instead of the expected {=A2}, and
-- The formula in H10 is {=G11} instead of the expected {=D6}.
WTF?? Why would it skip rows and columns like that?? BTW I'm in Excel 2007 SP3.
For now I'm doing this, which was the fastest way I found that worked:
Range("E5").FormulaArray = "=A1"
Range("E5:H10").FillDown
Range("E5:H10").FillRight
That works but is probably slower than the direct way would be. So -- why does setting the FormulaArray property to the Formula property skip referenced rows and columns as shown above?
The A1 formula is evaluated relative to the top left cell of the range you are populating. So A1 works fine in E5, but B1 is up 4 and left 3 from E5, so the formula entered into F5 refers to the cell up 4 and left 3, which is C1. This repeats for the other cells. The simple solutions is to use:
Range("E5:H10").FormulaArray = Range("E5:H10").FormulaR1C1
since that formula is the same for every cell.