How to copy and paste only non-blank cells in Excel?
Most of us may be suffered with this problem, when we copy a list of data which contain some blank cells, and then paste them to another column, the blank cells will also be pasted as well. This is very annoying when we don’t need the blanks and want to paste non-blank cells only. In this case, how could we copy and paste only non-blank cells in Excel quickly and conveniently? Here are some quick tricks for you to solve it:
With the Go To Special command, you can select all the data first, and then copy and paste them to another location.
1. Select your list of data that you want to use.
2. Then click Home > Find & Select > Go To Special, see screenshot:
3. In the Go To Special dialog box, check Constants option, see screenshot:
4. Then click OK, and only the value cells have been selected in the list.
5. And then copy and paste the data to a location that you want. And only the non-blank cell values have been pasted. See screenshot:
Note: This method only be available for the constants, it is not applied to the formula cells.
The Filter feature can help you filter the non-blank cells first, and then you can copy and paste them to another cells as you need.
2. Click Data > Filter, see screenshot:
3. Then click the drop down button at the right corner of the cell in the selected list, and uncheck the Blanks option under the drop down menu. See screenshot:
4. And then click OK, all the non-blank cells have been filtered out as following screenshot shown:
5. At last, you can copy the filtered data and paste them to any location you need.
Note: Both values and formulas are taken effect by using this way.
Select nonblank cells at once
|Click for free full featured trial in 30 days!|
To copy and paste only the non-blank cells, you can also apply the following array formula.
1. Besides your data, enter the following formula to a blank cell:
Note: In the above formula, A1:A15 is the data list that you want to use.You can change it to your need.
2. Then press Shift + Ctrl + Enter keys together, and then select cell B1, and drag the fill handle over to the range that you want to contain this formula, and all the non-blank cell values have been extracted. See screenshot:
3. As they are formulas, when you copy them to other place, you should copy and paste them as values.
Note: This formula only be available for the constants, not applied to the formula cells.
If you are interested in VBA code, you can execute the following code to finish this task.
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Copy and paste only non-blank cells in Excel
Sub PasteNotBlanks() 'Update 20140325 Dim rng As Range Dim InputRng As Range, OutRng As Range xTitleId = "KutoolsforExcel" Set InputRng = Application.Selection Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8) If InputRng.Columns.Count > 1 Then MsgBox "Please select one column." Exit Sub End If Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8) InputRng.SpecialCells(xlCellTypeConstants).Copy Destination:=OutRng.Range("A1") End Sub
3. Then press F5 key to run this code, a prompt box will appear to remind you selecting the data range that you want to use. See screenshot:
4. And then click OK, another prompt box will pop out to let you choose a cell to put the data.
5. Click OK to finish this code, and only the non-blank cell values have been pasted into your specified position.
Note: This code is only available to the constants.
Is there any much easier way than above? Of course, Kutools for Excel's Select Nonblank Cells utility can help you select the nonblank cells first, and then copy and paste them.
|Kutools for Excel, with more than 300 handy functions, makes your jobs more easier.|
After free installing Kutools for Excel, please do as below:
1. Select the cell range, and click Kutools > Select > Select Nonblank Cells. See screenshot:
2. Then the nonblank cells are selected, press Ctrl + C to copy them, then go to select a cell where you want to output the paseted result, press Ctrl + V to paste selected nonblank cells. See screenshot:
|Kutools for Excel: 300+ functions you must have in Excel, 30-day free trial from here|