0
Thanks

A few words of thanks would be greatly appreciated.

Excel - A Macro to copy and paste data in next blank cell

In this article we will show you an example of a Macro that can copy data in the next blank cell.




Example

If you have two sheets in a workbook: Sheet1 is for summary and Sheet2 is for the raw data and you need to update/insert/copy data in Sheet2 to Sheet1. Below is the incorrect sample macro code:

Sub Summarize()   
Range("A6:AT6").Select
Selection.Copy
Sheets("ImprovementLog").Select
Range("B283").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("B283").Select
End Sub


This code will work, but everytime you change data in Sheet2 the Sheet1 will only replace its data. But what you are probably looking for is that everytime you change data in Sheet2, it is also added (append) in Sheet1.

Solution

You need to know the last row used. In this case Range("B283"). Select finds the last used cell in column B and then select one cell below it:

lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row   
Range("B" & lMaxRows +1).select


Photo: © Everypixel
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
Related
This document, titled « Excel - A Macro to copy and paste data in next blank cell », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!