Copy paste data from 2 sheet to one sheet in same workbook

lady_alina

Board Regular
Joined
Feb 18, 2015
Messages
52
Hi,

I have a 3 sheeter excel, what I want is to copy fixed rows from one sheet named: Inv and copy next row each time I click the button from sheet: Details and paste values to specified cells in sheet: Reg. The code I have at present does that however it pastes the formula and not the values and fixed rows from Customer sheet from where I want next row on each click. Please help me to get the right code. Here is my code given below:

Code:
Private Sub CommandButton1_Click()Application.ScreenUpdating = False
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Dim DestRow As Long
    Set ws1 = Sheets("Details")
    Set ws2 = Sheets("Inv")
    Set ws3 = Sheets("Reg")
    DestRow = ws3.Cells(Rows.Count, "A").End(xlUp).Row + 1
    ws1.Range("A4").copy ws3.Range("A" & DestRow)
    ws1.Range("B4").copy ws3.Range("D" & DestRow)
    ws1.Range("C4").copy ws3.Range("G" & DestRow)
    ws2.Range("B13").copy ws3.Range("N" & DestRow)
    ws2.Range("H13").copy ws3.Range("L" & DestRow)
    ws2.Range("I28").copy ws3.Range("J" & DestRow)
    ws2.Range("H15").copy ws3.Range("K" & DestRow)
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
See if this does what you want.

Code:
Private Sub CommandButton1_Click()Application.ScreenUpdating = False
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Dim DestRow As Long
    Set ws1 = Sheets("Details")
    Set ws2 = Sheets("Inv")
    Set ws3 = Sheets("Reg")
    DestRow = ws3.Cells(Rows.Count, "A").End(xlUp).Row + 1
    ws1.Range("A4").copy 
    ws3.Range("A" & DestRow).PasteSpecial xlPasteValues
    ws1.Range("B4").copy 
    ws3.Range("D" & DestRow).PasteSpecial xlPasteValues
    ws1.Range("C4").copy 
    ws3.Range("G" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("B13").copy 
    ws3.Range("N" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("H13").copy 
    ws3.Range("L" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("I28").copy 
    ws3.Range("J" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("H15").copy 
    ws3.Range("K" & DestRow).PasteSpecial xlPasteValues
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks JLGWhiz it helped in pasting the values, however from sheet "Details" I need next rows and from Sheet "Inv" I need to copy fixed rows each time I click the command button. Can you please help with this as well. I had written this in my original question also but may be I wasn't very clear sorry for that.
 
Upvote 0
Thanks JLGWhiz it helped in pasting the values, however from sheet "Details" I need next rows and from Sheet "Inv" I need to copy fixed rows each time I click the command button. Can you please help with this as well. I had written this in my original question also but may be I wasn't very clear sorry for that.

If you mean that you want to advance the source row each time you click the button, I am not sure that can be done. A procedure could be written so that it would continue in a loop to copy cells from those same columns and increment the row by one each time. But you would need to provide some kind of criteria that could be used to limit the number of times it copies to only what is needed. If you want to copy until the source column is blank, that would be OK. That would be something that can be coded.
 
Upvote 0
Thanks for your reply and sorry for not making my concept very clear. what I want is to fixed rows for copying in sheet Inv and fixed columns but not rows. Check the code below may be it'll explain you more.

Code:
Private Sub CommandButton1_Click()Application.ScreenUpdating = FalseDim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Dim DestRow As Long
    Set ws1 = Sheets("Details")
    Set ws2 = Sheets("Inv")
    Set ws3 = Sheets("Reg")
    DestRow = ws3.Cells(Rows.Count, "A").End(xlUp).Row + 1
    ws1.Range("A4").copy                                                     ---------------------on next click it should copy A5 then A6
    ws3.Range("A" & DestRow).PasteSpecial xlPasteValues
    ws1.Range("B4").copy                                                    ---------------------on next click it should copy B5 then B6
    ws3.Range("D" & DestRow).PasteSpecial xlPasteValues
    ws1.Range("C4").copy                                                    ---------------------on next click it should copy C5 then C6
    ws3.Range("G" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("B13").copy                                                    ---------------------this should be fixed rows for copying
    ws3.Range("N" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("H13").copy                                                    ---------------------this should be fixed rows for copying
    ws3.Range("L" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("I28").copy                                                    ---------------------this should be fixed rows for copying
    ws3.Range("J" & DestRow).PasteSpecial xlPasteValues
    ws2.Range("H15").copy                                                    ---------------------this should be fixed rows for copying
    ws3.Range("K" & DestRow).PasteSpecial xlPasteValues
Application.ScreenUpdating = True
End Sub

However all should be pasted in the next blank available row in Reg Sheet
 
Last edited:
Upvote 0
Can anybody reply to the above question and to this new question please, I really need help on this one. Apart from the above question I need one more help:

From sheet: Inv I want to copy specific rows and paste in specific rows based on one cell value. For example: If cell value = D/22/E then A2 will be pasted in H13 "DestSheet", B2 will be pasted in G4 "DestSheet" and C2 will be pasted in D33 "DestSheet". See the table below

Customer NameAddressPhone #Ref#
AABC99999A/99/A
BDEF88888D/22/E
CXYZ77777R/44/W
DUVW66666E/55/E

<tbody>
</tbody>


I know this can be done using the above formula but I don't know how to put the criteria of cell value.


Hope to get an answer soon.
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,380
Members
449,097
Latest member
Jabe

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