How to use EVALCELL() with YEAR() in visio vba - vba

I'm running into this problem with shape formulas. If I do this:
YEAR(NOW())
I get the result: 2022.0000 which is what I expect.
However, let's say I have two shape data rows: Prop.Foo and Prop.Bar.
Prop.Foo = YEAR(ARG("A"))
Prop.Bar = EVALCELL("Prop.Foo","A",NOW())
I get a #VALUE! error in the result of Prop.Bar, and I don't understand why. Shouldn't I get 2022.0000?

Related

Vlookup to return blank instead of 0 or #N/A

I am using vlookup to get data from a source but I want the result to be blank instead of 0 or N/A when there is no vlookup value. So far it gives me an error. My code:
ws1.Range("H2:H" & lastrow3).Formula = "=IF(ISNA(VLOOKUP(C2,'[NOT OK.xlsx]Sheet1'!F:H,3,FALSE))+(VLOOKUP(C2,'[NOT OK.xlsx]Sheet1'!F:H,3,FALSE)=""),"",VLOOKUP(C2,'[NOT OK.xlsx]Sheet1'!F:H,3,FALSE))"
Edit (Still it does not run)
ws1.Range("H2:H" & lastrow3).Formula = "=IFERROR(VLOOKUP(C2,'[NOT OK.xlsx]Sheet1'!F:H,3,FALSE),"")"
I could emulate your example with a sample code, because you didn't provide a data to testing purposes.
The formula that worked:
=IFERROR(LOOKUP(B11;A1:A9;B1:B9);"")

Match function in VBA code

I'm trying to perform the following task using VBA: find a cell in table head that contains "Total number" title, return its column number, then find a cell on the intersection of raw with given number and column with returned number, and finally assign the value from this cell to a variable. Then wrote the value of this variable to another cell.
For example, suppose that the title "Total number" is in the AL column, then I'm trying to assign x = AL177 and then AM173 = x.
In a fact it is just a small part of more complex task, but unfortunately I can't deal with this fraction.
I wrote
Sub script()
Dim x As Integer
x = Cells(177, Application.WorksheetFunction.Match("Total number", ActiveWorkbook.Sheets("sheet name").Range("2:2")))
Worksheet("sheet name").Range("AM173").Value = x
End Sub
I need to specify sheet name exactly (not just active sheet or something else) since some time later I'm going to execute it from another sheet.
When I try to run it Excel gives me an error:
"Compile error: Sub or Function not defined"
Can anyone explain what is wrong with my code and how it should be done?

Excel Summing over Rows with for loop - Type mismatch error

so I am currently working on an Excel sheet where I have to calculate confidence intervals. Long story short, I think the only way I can do this automatically, is to write vba code. The first step would be to calculate the average of the cells in a column for several columns in the sheet. What I did:
Dim temp As Double
temp = 0
Dim it_row As Long
for it_row = 1 to 100
if IsBlank(Sheet.Cells(it_row,it_col)) then
temp = temp + 0
else
temp = temp + Sheet.Cells(it_row,it_col).Value
end if
next it_row
Dim Average As Double
Average = temp/100
'writing average in another cell
This code does not work, as the compiler returns Type missmatch, error code 13
in the line
temp = temp + Sheet.Cells(it_row,it_col).Value
I tried to do a CDouble(Sheet.Cells(it_row,it_col).Value) but that did not work.
Any help is appreciated, as I am quite desperate because googling did not really help me.
I should mention that I do have to use vba and this code because this is part of a bigger automated process and my supervisor said I must use vba for automation in the next step.
The Average and Sum Excel Functions ignore text, boolean, and empty values:
Average = Application.Average(Sheet.Cells(1, it_col).Resize(100))
Check
Sheet.Cells(it_row,it_col).Value
...with
if isnumeric(Sheet.Cells(it_row,it_col).Value)
...before adding it to a double type value. If that check fails, then you can chose to skip it or treat it as sth. else.
I would've added this as a comment, but I don't have enough rep. to add comments.

How to get the number of the first row of a range in OpenOffice Calc (BASIC)

So I have been converting a VBA code to OpenOffice BASIC and a simple task as getting the number of the first row of the range has been consuming hours of research.
in VBA:
Cells(3,2) or "mr" is a cell with an input of the kind "A5:G7", so first I splitted the string in a array with A5 and G7.
Rangesplit = Split(Cells(3, 2), ":")
FirstRow = Range(Rangesplit(0)).Row
So far in OpenOfficeBasic:
Rangesplit(mr,":")
I have not been able so far to determine the row and I want to know which function allows me to do it.
The following functions will probably help you:
Row_int = oCell.getCellAddress.Row
Col_int = oCell.getCell

Excel VBA Percentile using Application Function with multiple criteria

I have the below formula working fine over large ranges of data in Excel 2007.
In all cases Range1, Range2 and ArrayRange are the same start and end rows.
Working:
=PERCENTILE(IF(((Range1=Value)*(Range2=Value2)),ArrayRange),0.9)
When I'm updating the formula within a macro, I can't seem to figure out the correct way to formulate the above using VBA.
Can anyone assist with the below?
Not Working:
90thPercentile = Application.Percentile(((Range1 = Value) * (Range2 = Value2), ArrayRange), 0.9)
90thPercentile = Application.Percentile(If(Range1 = Value,IF(Range2 = Value2, ArrayRange))), 0.9)
many thanks
Nik
You can't use arrays like that in VBA. You'd have to use Evaluate and pass the formula string:
90thPercentile = activesheet.evaluate("PERCENTILE(IF(((Range1=Value)*(Range2=Value2)),ArrayRange),0.9)"