I am trying to get some code to print the active sheet based on the value of cell "B5" in Excel/VBA, if the value of B5 is 0 then the macro crashes and shows an error.
Is there a way to get this to just skip to the next line if the value of B5 is 0?
iNumCopies = Range("B5").Value
ActiveSheet.PrintOut Copies:=iNumCopies
Related
Here's my formula for the cell K37:
=IFERROR(1/(1/ArrayFormula(sumifs($H37:$H,$E37:$E,"ABC",MONTH($G37:$G),1))))
the cell K37 returns nothing (it's blank) when there's no cells in $E37:$E range with the "ABC" criteria and some value in corresponding $H37:$H range's cell. And it's fine!
But how do I force the formula to return 0 instead of just a blank cell if there's at least one cell in $E37:$E range, satisfying the "ABC" criteria with the actual $0.00 value in corresponding $H37:$H range's cell?
E G H K
37 ABC Jan-1 $0.00 blank (but I want it to be 0)
38
39
A way:
K37
=ARRAYFORMULA(IF(COUNTIFS($E37:$E,"ABC",MONTH($G37:$G),1),IFERROR(1/(1/SUMIFS($H37:$H,$E37:$E,"ABC",MONTH($G37:$G),1)),0),""))
Check if value exists, if #DIV/0! return 0, otherwise return blank.
I'm trying to code a script where a counter increment of 1 every time one condition is false, otherwise it's equal to 0.
The condition is a boolean output of the function CROSS().
I've tried:
1° version
var countSma50 = 0
countSma50_=countSma50
iff(cross(open, sma(close, 50)), countSma50=0, countSma50=countSma50_+1)
but when I plot countSma50 I obtain a line adding 1 from the first bar of the chart up to the last, countSma50 never return to 0.
or
2°Version
if cross(close,sma(close, 50))==true
countSma50+=1
else
countSma50=0
but the compiler return to me " Syntax error at input 'countSma50'."
The two script give me errors or wrong counter value..
The goal is to create a counter increasing of 1 at every bar, resetting itself every time the close crosses under/above the single moving average (sma).
Anyone can help me?
The second version was almost there, note that variables declared in the local scope are not visible from the global context of the script, declare the variable in the global scope first and re-assign later, the script below reset the value to 0 if there is a cross() trigger, otherwise will keep counting every bar:
//#version=4
study("My script")
var int countSma50 = 0
if cross(close,sma(close, 50))
countSma50 := 0
else
countSma50 += 1
plot(countSma50)
I am trying to build a spreadsheet that keeps track of my inventory. I want to use the First In First Out approach and need the formula to solve the following problem. I want to subtract the value 16 from the list of stocks over multiple rows.
Value= 16
Column A --> Column B
10 0
5 0
2 1
3 3
12 12
delete everything in B column and use this ArrayFormula like:
=ARRAYFORMULA(
IF(IF(A4:A="", ,{B1; (SUMIF(ROW(A4:A), "<="&ROW(A4:A), A4:A)-B1)*-1})>A4:A, 0,
IF(IF(A4:A="", ,{B1; (SUMIF(ROW(A4:A), "<="&ROW(A4:A), A4:A)-B1)*-1})>0, A4:A-
IF(A4:A="", ,{B1; (SUMIF(ROW(A4:A), "<="&ROW(A4:A), A4:A)-B1)*-1}), A4:A)))
Sample below:
Subtract: B2 = number [16]
Subtract: B3 = formula =B2-A2. Copy down.
Out: C2 = formula =IF(B2>A2,0,IF(B2>0,A2-B2,A2)). Copy down.
AL-CHE-P1-1518 --- 270
AL-CHE-P2-1318 --- 280
AL-MAT-P1-1218 --- 280
AL-MAT-P4-0918 --- 40
all these data are inside same cell C2, my aim is to derive a formula to sum
270+280+280+40
in cell D2
tried regextract(c2,"\d(.*)\n") but only the first "270" is extracted, I need help, searched through all forums, couldn't get exact match, it will save me huge time if anyone could give me some hint on how to derive the sum inside same cell string
As far as I know, you can only accomplish this via a UDF:
Function ReturnSum(rng As Range) As Long
Dim arr As Variant
arr = Split(rng.Value, Chr(10) & Chr(10))
For i = 0 To UBound(arr)
ReturnSum = ReturnSum + Trim(Split(arr(i), " --- ")(1))
Next i
End Function
=SUMPRODUCT(ARRAYFORMULA(REGEXEXTRACT(SPLIT(C2,CHAR(10))," \d+")))
In Excel the formula is a bit more complicated and an array formula:
=SUM(IFERROR(--MID(TRIM(MID(SUBSTITUTE(A1,CHAR(10),REPT(" ",99)),(ROW($XFD$1:INDEX(XFD:XFD,LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1))-1)*99+1,99)),FIND("---",TRIM(MID(SUBSTITUTE(A1,CHAR(10),REPT(" ",99)),(ROW($XFD$1:INDEX(XFD:XFD,LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1))-1)*99+1,99)))+3,99),0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when Exiting Edit mode.
I was trying to use the Lua if function to represent the result with a “*” in front of the value under a circumstance using an if function.
fefec C2
--------------
2 *2
3 3
When the value in Column 1 (fefec) is smaller than 3, then it is shown as * with the value entered in C2. When the value in C1 is equal or greater than 3, it is shown the actual value in C2. The code I wrote is
(function()
if [f#fefec] < 3 then
return "*[f#fefec]"
else return [f#fefec]
end
end)()
But for the first row, I got *(2.000000000000), how can I get rid of these 0s after 2?