Copy & paste to empty row in seperate workbook

mattyads05

New Member
Joined
Aug 1, 2016
Messages
5
Hi all.

Long time listener, 1st time caller.
I am still learning a lot every day with VBA, having only recently returning to a position that requires me to use it again, and I didnt know much before!

I have a UserForm which is populating data entered into 'row 2' on 'sheet 1' which I need to be copied and pasted into the next blank row on 'sheet 1' in a different workbook.

I have managed to get the userform to submit the data by recording a macro of me selecting a row and then opening the new workbook and pasting it, but I cannot find the piece of code that will select an empty row, at least that I can get to work.

I will post what I have below, can anyone help at all please?

Private Sub CommandButton1_Click()
Rows("2:2").Select
Selection.Copy
ChDir "G:\Shortcuts\RCC\TRAINING SERVICES\Training & Quality\Training WIP\Matt"
Workbooks.Open Filename:= _
"G:\Shortcuts\RCC\TRAINING SERVICES\Training & Quality\Training WIP\Matt\Feedback results.xlsm"
Rows("2:2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A3").Select
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
There is no error processing.
Hope this helps.

Code:
Private Sub CommandButton1_Click()
Dim wb1 As Workbook, wb2 As Workbook
Dim LR As Long

Set wb1 = ThisWorkbook
 wsb1.Sheets("Sheet1").Rows("2:2").Copy
 
Workbooks.Open Filename:= _
"G:\Shortcuts\RCC\TRAINING SERVICES\Training & Quality\Training WIP\Matt\Feedback results.xlsm"
Set wb2 = ActiveWorkbook
LR = wb2.Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
 wb2.Sheets("Sheet1").Rows(LR).Select
 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
 :=False, Transpose:=False
 wb1.Sheets("sheet1").Activate
 Range("A3").Select
 End Sub
 
Upvote 0
Thanks for getting back to me.

I am getting an error message for this part of the code you gave me.

Not sure what it is doing now, so I have no idea how to fix it.

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Sheets("sheet1").Activate
Range("A3").Select
End Sub
 
Upvote 0
wsb1.Sheets("Sheet1").Rows("2:2").Copy

Sorry,this is not wsb1, correct variable is wb1.
Please try again.
 
Last edited:
Upvote 0
Thanks. I made the correction. I am getting a debug on the following line of code

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

I am not sure what could be going wrong here, any ideas?

Thank you for your help, I really do appreciate it.
 
Upvote 0
I didn't get any errors...
Please try this new one.
Code:
Private Sub CommandButton1_Click()Dim wb1 As Workbook, wb2 As Workbook
Dim LR As Long


Set wb1 = ThisWorkbook
 
Workbooks.Open Filename:= _
"G:\Shortcuts\RCC\TRAINING SERVICES\Training & Quality\Training WIP\Matt\Feedback results.xlsm"
Set wb2 = ActiveWorkbook
LR = wb2.Sheets("sheet1").Cells(Rows.count, 1).End(xlUp).row + 1
 wb2.Sheets("Sheet1").Rows(LR).Value = wb1.Sheets("Sheet1").Rows("2:2").Value
 wb1.Sheets("sheet1").Activate
 Range("A3").Select
 End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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