Excel - How to leave cell blank instead of 0? [duplicate] - excel

This question already has answers here:
Pulling data from big excel datatable with incremental column in Vlookup or IndexMatch without zeros
(2 answers)
Closed 6 years ago.
I'm not using a numerical formula. All I have is a simple reference to another cell.
=(Sheet1!D8)
If that cell is blank, I want to have the cell on this page blank too, not a 0. How do I do that? I want it to appear empty to anyone, not just me, so I don't think simply editing excel settings would work? None of my google search results, including MS office site, have been helpful.

My suggestion:
=IF(ISBLANK(Sheet1!D8),"",Sheet1!D8)
You can force a formula to evaluate as text instead of as a number by adding '& ""' to the end like below, but if you are dealing with numbers this isn't great.
=(Sheet1!D8)&""
See this answer for other ideas.

Related

How do I enter a formula in VBA? [duplicate]

This question already has an answer here:
Excel VBA Formula German/French/Italian/Russian/Dutch/Foreign Function
(1 answer)
Closed 3 years ago.
I'm making a bot that erases certain columns and fills them in with new data. By erasing the data, the formula becomes
=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!#REF!,'AP query'!L:L,0)),"Non PO")
So I tried making a macro and filling the cell with the formula but it says there's an error. Is there a fix or another way to enter the formula into the the cell using macros?
Range("B3").Formula = "=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!C3,'AP query'!L:L,0)),"Non PO")"
srcWorkbook.Worksheets("Findings").Range("B3").Copy
srcWorkbook.Worksheets("Findings").Range("B3:B" & LR).PasteSpecial xlPasteFormulas
When you wish to use a string in a formula =IF(A1="Hi",... in VBA, just "double up" the quotes:
Range("B3").Formula = "=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!C3,'AP query'!L:L,0)),""Non PO"")"
Because, as VBA compiles that line, it'll hit the first quote at "Non Po" and think that's the end of the line. So (...trying to visualize it), it'd be reading that line like your formula is:
=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!C3,'AP query'!L:L,0)),
Tangiental tip - sometimes when I hit similar issues, even just pasting the code here on SO, and formatting it as code, helps because as you can see in your post, the Non PO is a different color, but all formulas (strings maybe?) should be the same (all red, as in the answer I posted above).

Excel - Refer to same cell above for two spaces, increment cell reference by 1, repeat pattern [duplicate]

This question already has an answer here:
Drag a formula down with Row changes by another interval other than one
(1 answer)
Closed 5 years ago.
This is a weird incrementing problem, and I've tried switching to R1C1 cell referencing but Excel doesn't recognize formulas to refer to those cells so I'm back.
So say I've got cell C2800, and I need this to be =C1109. Next, I need cell C2801 to also =C1109. I then need this pattern to repeat as I drag. Something like this
=C1109
=C1109
=C1110
=C1110
=C1111
=C1111
...
I've tried the drag down straight but excel thinks this is a flat cell incrementer and simply adds 1 each movement. So essentially I need a formula for a cell refer to a position 1691 spots directly above, and then 1692 spots directly above, then 1691, then 1692, continue and repeat. Let me know if any of you know how to make this feasible
Use INDEX():
=INDEX(C:C,INT((ROW(1:1)-1)/2)+1109)
Where /2 is the repetition wanted and the +1109 is the starting row.

Excel Formula to add text/word to a percentage result [duplicate]

This question already has answers here:
Concatenate percentages in Excel
(2 answers)
Closed 2 years ago.
I have a formula in 1 cell
=(A6-B6)/B6
Which results to -0.105243123560658in cell C6. A6 has the new sales amount and B6 has the old sales amount. I'm trying to get the result formatted like:
Difference is 10%
I have 2 problems
How to get the decimals turn into non-decimal number (I'm already researching on this)
How to add a text/word to a calculation result like adding "Difference is " to the (A6-B6)/B6 calculation result.
This I have tried to research and the only solution I can find involves using additional cells. Is there a way to do this with using only 1 cell ($C$6)? I tried
="Difference is "&(A6-B6)/B6
but I'm getting Difference is -0.105243123560658 instead. Also tried:
="Difference is "&($B$6-$C$6)/ABS($C$6)
You need the TEXT function:
="Difference is "&TEXT(ABS(A6-B6)/B6,"0%")

VBA_Using UsedRange.Count but failed [duplicate]

This question already has answers here:
Find last used cell in Excel VBA
(14 answers)
Closed 6 years ago.
I met a little problem when I use:
Count_line = ActiveSheet.UsedRange.Rows.Count
to count how many lines do I have in a worksheet. It can not give me the correct number. Can it be influenced by the format of the cells? Cause I've different coulour to highlight some important columns.
If you've got sime idea, please leave a comment. Thank you!
UsedRange.Rows.Count is not a reliable way to pull the last row, as it doesn't account for empty rows at the start of your sheet. Assuming you are finding the last row with text in it, use the End method to find the row.

define a range in VBA [duplicate]

This question already has answers here:
Find last used cell in Excel VBA
(14 answers)
Last not empty cell (column) in the given row; Excel VBA
(2 answers)
Closed 8 years ago.
I have a range of data that will be between columns B and D inclusive.
I can get the top left most range as this will be constant, the only thing that varies is the bottom right cell.
I tried obtaining the bottom right cell via using xltoright and then xltobottom. However I am having difficulties obtaining the cell address of this bottom right cell.
Has anyone come across this problem and if so how did you over come the issue?
change xltoright and then xltobottom, to : xltoleft and then xlUp.
Check the answers you get from it in the immédiate window of VB editor (Ctrl+G)
if still doesn't work maybe use:
Range(Range_Adddress).cells.(Range(RangeAddress).cells.count).address
to get to the last cell's address of your range (I named it Range_Address, which has to be a string in the example).
Does this help you?

Resources