Trying to get the minimum value in a range excluding the 0's.
Cells(PoleRow, 4).Formula = "=MIN(IF($AK$" & PoleRow & ":$CH$<>0" & PoleRow & "))"
I am not sure if I have the <>0 in the right place or not. I always thought that it should be placed after the column_num.
You are correct, it is in the wrong place and you want to use FormulaArray and you need to return something with the IF:
Cells(PoleRow, 4).FormulaArray = "=MIN(IF($AK$" & PoleRow & ":$CH$" & PoleRow & "<>0,$AK$" & PoleRow & ":$CH$" & PoleRow & "))"
Related
struggling to get the parenthesis in the right spot. this is formula in a specified range in vba macro
Range("C" & i).Formula = "=INDEX($C$1:$C$2,MATCH(" * "&TRIM(RIGHT(A" & i & ",LEN(A" & i & ")-FIND(" - ",A" & i & ")))&" * ",$A$1:$A$2,0),0)"
Your formula should be..
.Formula = "=INDEX($C$1:$C$2,MATCH(""*"" & TRIM(RIGHT(A8,LEN(A8)-FIND(""-"",A8)))& ""*"",$A$1:$A$2,0),0)"
I'm trying to do a VBA code to accomplish 2 things as follows:
Count how many characters there is on cell A1, using the formula LEN(A1) and one the last line, I'm trying to have the formula RIGHT(LEFT(A1;Q1-2);6) on cell J1
Please follow down my VBA code so far:
LR = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To LR
cel = "A" & i
cel2 = "P" & i
cel3 = "Q" & i
Range("P" & i).Formula = "=LEN(" & cel & ")"
Range("J" & i).Formula = "=RIGHT(LEFT(" & cel & "," & cel3 & "-" & 2 & ")," & 6 & ")"
Next i
It seems something silly what is missing, however, I couldnt manage to solve it so far
Thanks in advance
You’re missing a Right, and some other things
Range("J" & i).Formula = "=RIGHT(LEFT(" & cel & "," & cel3 & "-2), 6)"
I am trying to average a column but only if the value is greater than zero. I then want it to put the information in the next blank cell in that row.
The below code was working as a simple Average but I want it to exclude any values of zero from the above cells.
With Range("D2")
.End(xlDown)(2, 1) = _
"=AVERAGE(" & .Address & ":" & .End(xlDown).Address & ")"
End With
I Tried with the following code to have it as if the cell address is greater than zero. But it keeps giving me an error to debug?
With Range("D2")
.End(xlDown)(2, 1) = _
"=AVERAGEIF(" & .Address & ":" & .End(xlDown).Address & "," & Cell.Address & " > 0," & .Address & ":" & .End(xlDown).Address & ")"
End With
Any help would be great.
Thanks
Al
Your syntax for the formula is wrong.
You need to create a formula like
=AVERAGEIF(D2:Dxx, ">0")
So use this
With Range("D2")
.End(xlDown)(2, 1) = _
"=AVERAGEIF(" & .Address & ":" & .End(xlDown).Address & ","">0"")"
End With
I really appreciate if anyone could help; I've been working on this for a while...
I just want to define the formula of countif in a cell, here is the code:
Range("E" & PLrowstart).Formula = "= CountIf($B$PLrowstart:$B$PLrowend" & ",B2)"
PLrowstart and PLrowend are integer variables I set before the line. The range for count if is range("B" & PLrowstart & ":B" & PLrowend). I've also tried other ways, none worked...
TIA.
Range("E" & PLrowstart).Formula = "= CountIf($B$" & PLrowstart & ":$B$" & PLrowend & ",B2)"
Try this
Sub SetFormula()
PLrowstart = 2
PLrowend = 4
Range("E" & PLrowstart).Formula = "=CountIf($B$" & PLrowstart & ":$B$" & PLrowend & ",B2)"
End Sub
UPDATE:
Got a new issue with a formula, can't quite get it to work because of text in the formula, the formula (as taken from excel) should be,
=IF(D2<=0,"No Sales Price",E2/D2)
I have tried as many combinations as I can think of but the "no sales price" is causing an issue with the quotation marks. My current code is
For i = 2 To LastRowG
Range("Q" & i).Formula = "=IF(D" & i & "<=0," & "(No Sales Price)", & "(E" & i & "/D" & i & "))"
Next i
have had a look around but been unable to see any resolutions to the problem, any enlightenment will be met with the greatest appreciation
EDIT:This was fixed by inserting the following lines;
For i = 2 To LastRowG
Range("Q" & i).Formula = "=IF(D" & i & "<=0," & Chr(34) & "No Sales Price" & Chr(34) & "," & "E" & i & "/" & "D" & i & ")"
Next i
The Chr(34) inserts the ASCII character appertaining to that number which just so happens to be ". The program doesn't read it as having typed in the quote marks and continues to read the line of code correctly but then places the "no sales price" correctly in the formula.
It will output the line as the formula is intended to be and the Chr(34) is like writing ""No Sales Price"" without the inevitable "expected end of statement" error
What I suggested will result in something like this:
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Cells(LastRow + 1, 3).Formula = "=SUM(C1:C" & LastRow & ")"
Extra 1
Is it possible to use this formula to enter the word Total in the cell to the left?
Range("B" & LastRow + 1) = "Total"
Extra 2
One more just to push my luck, how about copying a formula all the way down a column the the last cell? =G2*57.5 copied until the last row in I
LastRowG = Cells(Rows.Count, "G").End(xlUp).Row
For i = 2 To LastRowG
Range("I" & i).Value = "=G" & i & "*57.5"
Next i