IF Function vba - vba

I need a macro that can do this:
If column AB5 has a blank cell, then then column A5 will take the value from column U5.
if column AB5 is not a blank cell (contains text), then column A5 will take the value from AC5.
This will run for all the data at column AB
I tried to use IF function, =IF(ISBLANK(AB5), U5, AC5) but it will reflect the wrong data if the cell contains text where they will still take U5 value.
Ideally is if it can be done using macro, but IF function is also fine too!
Please help thanks!

I'd guess that your cells are not truly blank. My guess would be that AB5 has formula in it. Try:
=IF(LEN(AB5)=0,U5,AC5)
Edit
If it has a single space in there rather than being empty:
=IF(LEFT(AB5,1)=" ",U5,AC5)
or
=IF(LEN(AB5)<2,U5,AC5)
Perhaps try reversing the formula:
=IF(LEN(AB5)<>0,AC5,U5)
=IF(AB5<>"",AC5,U5)
As they are all 3 letter acronyms try this one:
=IF(LEN(AB5)>2,AC5,U5)
A foolproof way to be sure that there are no spaces as input errors:
=IF(LEN(SUBSTITUTE(AB5," ",""))=3,AC5,U5)
Let me know if any of these work, I can mock up a VBA function for you if they don;t but they should work.

Your function
=IF(ISBLANK(AB5), U5, AC5)
should work fine. If you drag down the formula in the A Column, the numbers in the formula should change:
=IF(ISBLANK(AB6), U6, AC6)
etc. Is this happening? What is your formula in cell A6?

=IF(AB5="", U5, AC5)
try that, should work

Related

Swapping the placement of a character in a cell

I've been looking for a way to change the placement of a character within a cell with a macro, and have not been able to find exactly what I'm looking for. I've found ways to switch words (such as first name last name), but I need to switch a single character that is attached to the end of a number.
The report that's being filtered in registers negative numbers as:
2.00-
and I'm looking for an easy way to switch it to:
-2.00
as I am dealing with a massive number of records. Is there an easy macro that I can use to do this, or do I need to manually change these? Thanks in advance!
Select column then Text-to-Columns, Fixed width, Next, Advanced, Trailing minus for negative numbers, Ok, Finish.
With data in A1, in B1 enter:
=IF(RIGHT(A1,1)="-",-MID(A1,1,LEN(A1)-1),A1)
Create a new column and insert this formula. Replace A3 with the first cell in question, and then drag it down:
=IF(RIGHT(A3,1) = "-", LEFT(A3, LEN(A3)-1) * -1, A3)

Inserting vlookup function via vba adds brackets on column

I've got a problem with brackets in complex vlookup "insert function".
It's needed for a plan for each day of week. Because of slow performance of workbook I decided to turn on/off each day of plan, entire plan works but the column with expeditions. Code for part of "U" column is:
Range(Cells(firstm, "U"), Cells(lastm, "U")) = "=IF(RC2=0,IF(RC[-8]>0,
IF(ISERROR(VLOOKUP(G:G,Expedition!F:H,3,0)),R1C22,VLOOKUP(G:G,Expedition!F:H,3,0)),R1C22)
,IF(ISERROR(VLOOKUP(G:G,Expedition!F:H,3,0)),R1C22,VLOOKUP(G:G,Expedition!F:H,3,0)))"
It's quite messy, but it works :) at least in sheet.
The problem is that part of inserted formula in cell is
VLOOKUP(G:(G);Expedition!F:(H);3;0)
instead of
VLOOKUP(G:G;Expedition!F:H;3;0)
if only VLOOKUP is used, it works fine, I have no idea why in this example are those brackets.
Any ideas?
//edited for better understanding
Try to use either R1C1 or A1 reference style and specify the formula type, for example:
Range(Cells(firstm, "U"), Cells(lastm, "U")).FormulaR1C1 = "=IF(RC2=0,IF(RC[-8]>0, IF(ISERROR(VLOOKUP(C[7],Expedition!C[6]:C[8],3,0)),R1C22,VLOOKUP(C[7],Expedition!C[6]:C[8],3,0)),R1C22) ,IF(ISERROR(VLOOKUP(C[7],Expedition!C[6]:C[8],3,0)),R1C22,VLOOKUP(C[7],Expedition!C[6]:C[8],3,0)))"
edit: of course the relative references G:G etc have to be changed to relative references C[7]. C[7] becomes G:G while C7 becomes $G:$G.
Well, it perfectly works.. when I'm using that in half of the code, why haven't I used that for columns?.. :) Thank you!

How to modify excel autofill?

I have got a timetable. I want to transpose data in rows to column (rather using formulas) in the way which is shown on this picture.
In first row (AU,KM,GK,MZ) are teachers, in second one are rooms.
In B23 cell is formula: "=INDIRECT(ADDRESS(COLUMN(Q2),ROW(Q2)))"
in B24 "=INDIRECT(ADDRESS(COLUMN(R2),ROW(R2)))",
in B25 "=INDIRECT(ADDRESS(COLUMN(Q3),ROW(Q3)))",
in B26"=INDIRECT(ADDRESS(COLUMN(R3),ROW(R3)))"
I want to fill monday column, but excell autofill is not working like i would like - next formulas are for example q5,r5,q7,r7,q9,r9 instead of simple increasing this way -> q1,r1,q2,r2,q3,r3,q4,r4,q5,r5 etc.
How to fix it? Any help will be appriciated.
In B13:
=IFERROR(INDEX($7:$7,MATCH(A13,$5:$5,0)),"")
In B14:
=IFERROR(INDEX($8:$8,MATCH(A13,$5:$5,0)),"")
Then copy and fill both down.

Change #N/A to Blank cell

How can I change the #N/A to the blank cell if nothing in that cell?
Eg. =VLOOKUP(B19:B36;$TABLE.A1:C46;2;0)
I think I might need something like an ISERROR check but I don't 100% know what I'm doing.
If we're talking about Excel 2010 and later you can use IFERROR:
=IFERROR(VLOOKUP(B19:B36;$TABLE.A1:C46;2;0);"")
You can also put text into the final string result
The question was misleading about the spreadsheet software as 2 different spreadsheets were originally stated in tags. However, it can be seen that the question is about OpenOffice Calc:
- Absolute sheet referencing ($ sign before the sheet name) is not possible in Excel.
- We also see a dot between the sheet name and the range, which is again not possible in Excel.
As in OpenOffice Calc you don't have IFERROR function, the only way is to repeat your main function twice in the following form (you can use both, ISNA and ISERROR, but I suggest ISNA as it's more specific and fits your case):
=IF(ISNA(YourFormula);"";YourFormula)
In your case something like:
=IF(ISNA(VLOOKUP(B19;$TABLE.A1:C46;2;0));"";VLOOKUP(B19;$TABLE.A1:C46;2;0))
You may want to make absolute reference to the range where you look for matching values, as I see you want to copy the formula down.
=IF(ISNA(VLOOKUP(B19;$TABLE.$A$1:$C$46;2;0));"";VLOOKUP(B19;$TABLE.$A$1:$C$46;2;0))
Since the cells will contain a formula this is about appearances, so Conditional formatting might suit, say if the cell background is white, for style choose Font > Font Effects > Font color white.
For this, select the relevant range - I have assumed D19:D36 - and Format > Conditional Formatting... and for Condition 1 choose Cell value is and equal to and:
ISNA(D19)

#NAME? error on correct Excel formula

NAME? error is the output for the formula shown bellow. $D$6 is a number. However whenever I click inside the formula and press 'intro' as if the cell had been modified, the formula returns the correct value.
=MROUND($D$6-9.1132,1/16)
If D6 value is less than 9.1132 you have a negative number in the left part. The right part of the formula has positive number, that's why you get the error. Please ensure both parts of your formula have the same sign. Here is the man page for this.
I had the same problem. Inserted the Formula with C# and saved it.
range.Formula = "=SUMME(A1:C3)";
When I opened the workbook it would show me the "#Name?"-Error. Once klicked in the cell manually it showed the correct formula, and when i left the cell it would show the correct calculated value instead of "#Name?"
I found out that it was a localization problem. I use the german Excel, but the formulas via Excel-Com-Interop-Library have to be inserted in english!
range.Formula = "=SUM(A1:C3)";
Once i changed this, everything worked well.