Change Cell Range Values Based On Value Of One Cell - vba

The below formula does not work. if c5 or c8 have values equal to "yes" then every cell in the range (excluding c5 and/or c8) will automatically equal "no". if both c5 and c8 = no, just calculate the percentage of yes's to no's. i will give you an example. we have 10 answers. c5 and c8 are both no, and everything else is equal to yes. that is 80%. if we have an n/a (instead of yes or no), we subtract the number of n/a's from the total and calculate the quotient. for example, say we have 10 answers, c5 and c8 are both no again, and we have 1 n/a. so the quotient would be 7/9=77 percent.
I even tried to generate a vba formula and it didn't work.
Pivate Sub Worksheet_Change(ByVal Target As Range
If Worksheet1.Range("C18").Value="Yes" Then
Worksheet1.Range(("C17:C23") - C18).Value = "No"
End if
End Sub
=If(OR(C5=“Yes,C8=“Yes”),”No”,[IFERROR((COUNTIF(C4:C23,"Yes”)-C5-C8)/(COUNTIF((C4:C23,"Yes”)-C5-C8)+(COUNTIF(C4:C23,"No”)-C5-C8)),””)])

Related

For Excel VBA, If B2 value did not change then A2 will keep same, If B2 is changed then A2 will increase by one

I need a VBA for the whole column B and A says that
if Value of Cell B2 did not change then A2 value will be the same
if B2 value is changed then A2 value will increase by one
Use this formula.
Put your staring number in A1.
Put this in A2:
=IF(B2<>B1,A1+1,A1)
And copy down.

VBA - If Loop for two sets of Data

So I have two columns of data and I want to add a date next to data that has two sets of values. So if A3 = Trucks and B3 = 2008 appear in the two columns I want C3 to have a date value of 11/1/2016. If these values A3 = Trucks and B3 = 2008 appear anywhere else in the data I want the date value to increase by 1 to 11/2/2016 and have that run until the data is fully queried.
This is what i understand from your question
if A3 = Trucks, B3 = 2008, C3 = 11/1/2016. then
if A10 = Trucks, B10 = 2008, then C10 = C3 +1 i.e. 11/2/2016
if my understanding is right, the below formula should work. Here is a google spreadsheet.
IF(MAX(--($A$1:A8=A9)*--($B$1:B8=B9)*ROW($A$1:A8))>0,OFFSET($C$1,MAX(--($A$1:A8=A9)*--($B$1:B8=B9)*ROW($A$1:A8))-1,0)+1,"New Date")
Please note the formula is an array formula i.e. press Ctrl+Shift+Enter after typing in cell. Also I have added an if clause, in case the item is appearing for the first time in the list, it will show "New Date".

Excel set cell list value to cell above based on condition

In Excel column D is of a list type. Cell D3 is correctly populated according to the list. When A4 is not null D4 must be equal to D3. This works fine when A4 is not null, however when A4 is blank I get a validation error. The idea is when I do not have a value in A4 nothing should happen in D4, i.e. D4 should also remain blank.
I have tried
=if(A4<>"",D3,"")

Nested 'For' cycle required

I have four cells in an Excel workbook:
A1
A2
A3
A4
A1 and A2 cells include starting values such as 5 and 7. A3 has an formula and evaluates a result using A1 and A2's values. A4 cell has a target value. An iterational operation continue up to A3 cell's value equal to A4's 0,0001 approximation. For each A1's differential increment A2 will change depending on its range.
Can anybody help me with VBA including nested 'For' cycles?
My sample workbook:
There is an add-in with excel that is built to do this, it's called the solver addin.
There's a good tutorial here that explains how it works.

Add Numbers Until Value Reached

I want to have a threshold value in one cell(A1) and take it as a reference for adding cells.
Suppose I have
A1 - 10
A2 - 4
A3 - 2
A4 - 3
A5 - 4
A6 - 6
I want to add cells based on A1(Threshold).
As A1 is 10, cells from A6:A5 should be added - Result:10
If A1 is 6 then cell A6 should be returned- Result:6
If A1 is 16 then cells from A6:A3 should be added - Result:19
Is this possible without VBA? Can i get count of number of cells in return along with sum?
I've added some progression SUM operation with ROW and OFFSET for the following. Note that I have modified and added to your sample data for more thorough results.
      
The SUM formula in C2 is =SUM(OFFSET($A$2,0,0,MAX(INDEX((SUBTOTAL(9,OFFSET($A$2, 0,0,ROW(1:99),1))<$A$1)*ROW(1:99),,))+1,1)) anf the COUNT is derived in D2 with =MAX(INDEX((SUBTOTAL(9,OFFSET($A$2, 0,0,ROW(1:99),1))<$A$1)*ROW(1:99),,))+1. TBH, I didn't experiment much with zeroes in the data as I was unsure whether you would want to count them in the progression or not.
You can use the INDIRECT() function.
=SUM(INDIRECT("A6:A"&ROUNDDOWN(A1/2,0)))
for the count use
=COUNT(INDIRECT("A6:A"&ROUNDDOWN(A1/2,0)))
It's hard to hit a moving target but for your revised parameters try the following.
=SUM(OFFSET($A$6,0-MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,)),0,MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,))+1,1))
 
=MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,))+1
While Excel expects to calculate in a 'down-and-to-the-right' progression, the OFFSET() function will accept parameters to both relocate the starting point and reshape the height and width of the range of cells being summed. Generally, working 'down-and-to-the-right' will allow to leave some breathing room for expansion but you will have to be very careful that you do not attempt to move upwards past row 1 (#REF! error).
OFFSET function
The formula could be simplified if there was any guarantee that nothing of numerical value was ever going to be below A6 but that point has not been addressed so my formulas halt the sum operation at A6.