I am working with a list of data where one or multiple cells in a row can be blank.
Lets say the list is cells A1, A2, A3, A4. I am trying to create a function that will do the following:
IF A1 has a value I want the cell to return A1.
IF A1 is empty then I want it to return A2.
IF A1 and A2 are both empty I want it to return A3.
If A1, A2 and A3 are all empty I want it to return A4.
first result on google: http://chandoo.org/wp/2014/01/15/find-first-non-blank-item-in-a-list-excel-formulas/
This formula returns the first TEXT cell for a range B1:B100:
=VLOOKUP("*", B1:B100, 1,FALSE)
* is a wild card in Excel. When you ask VLOOKUP to find *, it finds the first cell that contains anything.
NOTE: This approach finds first cell that contains any TEXT. So if the first non-blank cell is a number (or date, % or Boolean value), the formula shows next cell that contains text.
If you need to find non-blank that url gives the following solution:
If you want to find first non-blank value, whether it is text or number, then you can use below array formula.
=INDEX(B1:B100, MATCH(FALSE, ISBLANK(B1:B100), 0))
Make sure you press CTRL+Shift+Enter after typing this formula.
How this formula works?
ISBLANK(B1:B100) portion: This gives us list of TRUE / FALSE values depending on the 98 cells in B1:B100 are blank or not. It looks like this:
{TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE; ...}
MATCH(FALSE, ISBLANK(…), 0) portion: Once we have the TRUE / FALSE values, we just need to find the first FALSE value (ie, first non-blank cell). That is what this MATCH function does. It finds an exact match of FALSE value in the list.
INDEX(B1:B100, MATCH(…)) portion: Once we know which cell is the first non-blank cell, we need its value. That is what INDEX does.
As indicated in your comment on your question, you have 500 rows interspersed with blank cells. You want to fill blank cells with the value of the last non blank cell.
I'd write some VBA code that'd work as follows: select the range of cells you want to back fill and run this VBA:
Sub fillBlanks()
For Each c In Selection.Cells
If c.Value <> "" Then
lastVal = c.Value
Else
c.Value = lastVal
End If
Next c
End Sub
basically, if the cell is empty, use the value of the last non blank cell (if there were no blank cells above, it will remain blank). Else, if the cell is not empty, save this as the last non blank cell. Repeat for every cell in the selected range.
Step by Step instructions on using this vba code - for this sample worksheet:
Make sure the range is selected, press ALT+F11.
This should open the Visual Basic Editor:
Press F7, This should bring up the code for the activesheet. Paste the VB code from above:
Press F5 (or use the menu to run the code).
The end result should be as follows:
Select ColumnA:
HOME > Editing > Find & Select > Go To Special... > Blanks, OK, =, ↓, Ctrl+Enter.
You can just put a rank.eq formula in the column next to it, and do a vlookup to bring all of your data to the top. This will bring all of your data to the top.
For example, in the image below I am ranking using the percentage, I want to bring the cells with data to the top for presentation, I will hide all columns other than where my vlookups are.
This did the trick for me
=LOOKUP(2,1/(A1:A13<>""),A1:A13)
Source credit: here
Related
I've noticed a behaviour in Excel which doesn't intuitively make sense.
If any formula causes a cell to evaluate as a blank string, such as ="", then you copy that cell and paste as value so that the formula disappears - the cell will still count when included in a COUNTA formula. Until you press F2 to edit the cell, and then press Enter - then the cell will no longer be counted.
I can understand why COUNTA counts cells including a formula, but once you copy and paste a cell as a value, if the formula evaluated to blank, the cell should also be blank, at least intuitively. What's weird is that updating the formula causes the COUNT to decrease. This seems like a bug, but I wanted to put it on here to be sure this wasn't a weird feature I was missing.
Here are the steps I took to reproduce this (also in the image below):
Enter ="" into cells A1:A10
Select cells A1:A10 and Copy
Select cell A1 and Paste as Value
Select any cell within the range and press F2
Press Enter
The count in cell A11 will decrease by one
Alternatively to Step 4, if you select any cell within the range and press Delete, the count will also decrease.
The count in the image is 7 because I've tested Steps 4 and 5 several times - the count started at 10.
I am using the Office Insider program, so if it is a bug this may be the reason why.
Can anyone shed some light on this?
Not a bug.
="" returns an empty string, which is not the same as a truly empty cell. Copy/pasting values maintains the empty string.
Editing the cell with F2 and then Enter effectively renders the cell blank.
Here's an interesting little VBA test for more detail:
Sub Test()
With ActiveCell
.Formula = "=""""" ' enter ="" in the ActiveCell
Debug.Print TypeName(.Value) ' returns String
.Copy
.PasteSpecial xlPasteValues
Debug.Print TypeName(.Value) ' returns String
.Value = .Value
Debug.Print TypeName(.Value) ' returns Empty
End With
End Sub
So I have a column with blanks randomly throughout...I need a macro that would select only the blanks, and then in those blank cells paste in the value of the cell above it. The select part is obviously easy, but I keep getting errors about 'too many continuations' when trying to fill the formula down into the blanks. I included a picture, the first column is a 'before' and the second is how I want the column to look after the application of the macro.
If the macro needs to create a second column or something that's fine too, as long as the end result looks like it does in the picture. Thanks!
Picture to illustrate.
try,
sub fillblankfromabove()
dim blnks as range
with worksheets("Sheet1").Columns("E").Cells
set blnks = .specialcells(xlcelltypeblanks)
if not blnks is nothing then
blnks.formular1c1 = "=r[-1]c"
end if
.value = .value
end with
end sub
Another way to do this is to select all cells that you want included in this process, press CTRL + G, select Special, then select 'Blank Cells'. This will select all blank cells within your selected range. Then enter =[cell above] and press CTRL + ENTER and it will enter that formula into all selected cells.
I have a formula in cell c15 that I need to copy down the entire column. However, I want to copy the formula down one cell at a time, calculate the value and then paste special values over that cell.
I want to repeat the code below to calculate one cell at a time. I can't repeat until the last cell is empty because they are all empty except cell c15 so I'm not sure how to stop the loop.
Sub Macro5()
Range("c16:c3000").Formula = Range("c15").Formula
Range("c16:c250").Calculate
Range("c16:c250").Value = Range("c16:c250").Value
End Sub`
I'm trying to make a worksheet where one column automatically numbers based on the value of another cell.
If the cell in the first column says 'MSG', the value in the next cell, should be something like MSGRA15_00001, if in another row, the first cell is also MSG, the value in the next cell should become MSGRA15_00002.
If the value in the first column says SEL the returned value in the next column should be SELRA15_00001 and so on...
Cell numbering based on previous cell
Can anyone help me on this?
Thanks a lot!
Assuming your MSG/SEL-column is in range A1:A?, you can paste
=A1&"RA15_"&TEXT(COUNTIF(A$1:A1;A1);"00000")
Into B1 and then copy and paste it from there.
I am new creating macros and I usually record them but I'm having problems copying and paste as values to remove the formula from 3 highlighted cells
For example I have a formula on cell B3 C3 & H3 so I would like to highlight only those cells manually and then the macro can remove the formula on each like copy and paste as values on the same cells
I have tried with ActiveCell.Select but that only works for 1 cell not for multiple cells and also the problem is that I need to change to values different cells each day
Not sure I follow your question exactly but here is what I think your asking for.
You can loop through each cell that is selected and then set the cell value to it's current value which effectively removes all formulas. There are other ways to do this but I think this best answers your specific question.
Sub removeFormula()
For Each cell In Selection
cell.Value = cell.Value
Next cell
End Sub