If you try to copy multiple cell ranges on a worksheet that don't have the same number of rows or columns you get the following error message.
This action won't work on multiple selections, see picture above. What? The cell ranges above have the exact same size?
Yes, however, they also need to be on the same columns or rows.
The image to the right shows selections that share the same column letters, in this example column B and C.
If the selected cell ranges share the same column letters your selected cell ranges may have a different number of rows.
What do you mean? The following picture shows multiple selections that share the same column letters but each selection has a different number of rows.
The picture above shows three selections, the first selection contains one row, the second contains two rows and the third selection has 3 rows.
The same thing applies to cell ranges that share the same row numbers.
To sum it up, remember that the selections must share the same column letters or row numbers to be able to copy non contiguous cell ranges.
I need to copy multiple noncontiguous cell ranges that don't share the same column letters or row numbers? The following macro allows you to do that.
Copy non-contiguous cell ranges (Macro)
The picture above demonstrates a macro that allows you to copy non contiguous cell ranges. In this example, the selections are copied to destination cell F3.
The macro will show you a dialog box that allows you to select a destination cell. Each selection is then copied to the destination cell or the first empty cell below.
Visual Basic Macro
Set cellranges = Application.Selection
Set ThisRng = Application.InputBox("Select a destination cell", "Where to paste slections?", Type:=8)
For Each cellrange In cellranges.Areas
i = i + cellrange.Rows.CountLarge
Where to put the code?
Open the Visual Basic Editor (Alt + F11).
Click "Insert" on the top menu bar.
Click "Module" to insert a code module to your workbook. Module1 automatically appears in the VB Project window.
Paste the code into the code module.
Save your workbook as a macro-enabled workbook, the file extension looks like this: *.xlsm
Exit Visual Basic Editor.
How to use the macro
You simply hold CTRL key while selecting the cell ranges.
Then press Alt+F8 to see a list of macros.
Click "Run" button
A dialog box appears asking you for the destination cell.
That is it, the selections are copied to your destination cell.