Copy Selection Sheet1, Paste Values First Open Row Sheet2

sd2173

New Member
Joined
Feb 16, 2011
Messages
31
Good afternoon all,

I am trying to develop a simple macro to on button click transfer the data on sheet1 (for example called "Notes") to the first open row on sheet2(for example called "Log"). Below is where I am at right now, which gives me the result after clicking where I can see it shifts to the Log page but doesn't past values in the open row under the header. I also see when going back to Notes that it did select and copy.

I also wouldn't mind "cutting" the data from Notes so it is empty after the transfer.

Sub Button1_Click() Dim NextRow As Range
Set NextRow = Range("a" & Sheets("Log").UsedRange.Rows.Count + 1)
Sheets("Notes").Range("a2:g6").Copy
Sheets("Log").Activate
NextRow.PasteSpecial Paste:=xlValues, Transpose:=False
Application.CutCopyMode = False
Set NextRow = Nothing
End Sub

Data1Data2Data3Data4Data5Data6Data7
123xaaa111a5543
123yaaa222b6453
123xbbb333a8765
123ybbb444c4543
123yaaa555a2234


<tbody>
</tbody>


Any guidance is much appreciated, I don't know where I'm astray.

Regards,
Spencer
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try
Code:
Sub Button1_Click()
Dim NextRow As Long
NextRow = Sheets("Log").UsedRange.Rows.Count + 1
Sheets("Notes").Range("a2:g6").Copy
Sheets("Log").Range("A" & NextRow).PasteSpecial Paste:=xlValues
End Sub
 
Upvote 0
Excellent! Is there a simple way to do all cells in Notes because likely it will always be a different amount of rows. I tried replacing with "Sheets("Notes").Range("a:a:g:G").Copy", but when comes to pasting in Log unable to do so since "size" not same as from copy. Also, the majority of Notes columns will be based off formulas I plan to run down to row 1000 and add on to macro to replace after I cut pasted info. Sheets("Notes").Range("a:2:g:1000").Copy doesn't seem to do the trick either.

Appreciate the help!

Spencer
 
Upvote 0
try
Rich (BB code):
Sub Button1_Click()
Dim NextRow As Long, lr As Long
NextRow = Sheets("Log").UsedRange.Rows.Count + 1
lr = Sheets("Notes").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Notes").Range("a2:g" & lr).Copy
Sheets("Log").Range("A" & NextRow).PasteSpecial Paste:=xlValues
End Sub
 
Upvote 0
sd2173,

Personally I prefer to assign values directly rather than copy & pastespecial (where appropriate). To try this alternative approach (on a COPY of your data) use:

Code:
Sub Button1_Click()
Dim rFrom As Range
Set rFrom = Sheets("Log").Range("a2:g" & Range("A" & Rows.Count).End(xlUp).Row)
Sheets("Notes").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(rFrom.Rows.Count, 7).Value = rFrom.Value
rFrom.ClearContents
End Sub

MichaelM,

There's a possible pitfall in using UsedRange to count rows for LR. Look at what happens when your UsedRange doesn't start on Row 1.

Teeroy
 
Upvote 0
Hi Teeroy
Yep agreed and aware of the usedrange issue.
I generally avoid it and go with lastrow approach.
 
Upvote 0
Hi Michael,

I don't mean to say I don't use UsedRange myself; its good when you don't know which column contains the most rows. I found a neater way to use UsedRange that doesn't have the same pitfall, e.g.

Code:
With ActiveSheet.UsedRange
    LR = .Rows(.Rows.Count).Row
End With


Troy
 
Upvote 0
Hmm.....haven't seen it used that way....like it !!...(y)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top