Copy data from one sheet to another

hopentell

New Member
Joined
Jan 4, 2019
Messages
5
I have a basic sheet and want to copy cell data from one worksheet to another using a button created in VBA.

Sheets("SourceSheet").Range("A1").Copy Destination:=Sheets("TargetSheet").Range("D5")
Sheets("SourceSheet").Range("A3").Copy Destination:=Sheets("TargetSheet").Range("D6")
Sheets("SourceSheet").Range("C2:C6").Copy Destination:=Sheets("TargetSheet").Range("B7:B11")
Sheets("SourceSheet").Range("B2:B6").Copy Destination:=Sheets("TargetSheet").Range("A7:A11")
Sheets("SourceSheet").Range("C1").Copy Destination:=Sheets("TargetSheet").Range("B6")
Sheets("SourceSheet").Range("E5").Copy Destination:=Sheets("TargetSheet").Range("E5")

This 7 rows of data then will be repeated and want to be able to copy & paste these 7 rows and the button, so that when that button is pressed it then copies the data from the Source to the Destination for the next 7 rows of data.

So the first 7 rows will be order number 1 - you click the button created and it will then transfer the data to the source for printing
Then this needs to be copied so that so the rows 8-15 can also be copied by a single press of the button, hope this makes sense
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Sorry, I did not understand, you press the button once and copy the data according to your code. If you press the button a second time, what should happen ?, you can put the code of what must happen the second time.

Don't worry, I'll check both codes and create a new one so that it works as many times as you want to press the button, but I need to understand what happens in the second, third ...
 
Upvote 0
I want to be able to copy cells A7 to Q7 - into cells A8 to Q8 - when I copy these I want the button created to do the same tasks as before but now for the cells within A8 to Q8.
Example here - https://ufile.io/5sixg

So the button works for 7 rows of data, then when copied into the next 7 rows, the button also changes to do so.
Hope this makes sense and thank you.
 
Upvote 0
I want to be able to copy cells A7 to Q7 - into cells A8 to Q8 - when I copy these I want the button created to do the same tasks as before but now for the cells within A8 to Q8.
Example here - https://ufile.io/5sixg

So the button works for 7 rows of data, then when copied into the next 7 rows, the button also changes to do so.
Hope this makes sense and thank you.

Amended -

I want to be able to copy cells A7 to Q7 - into cells A8 to Q14 - when I copy these I want the button created to do the same tasks as before but now for the cells within A8 to Q14.
Example here - https://ufile.io/5sixg

So the button works for 7 rows of data, then when copied into the next 7 rows, the button also changes to do so.
Hope this makes sense and thank you.
 
Upvote 0
The most practical thing is that you only have one button, select cell A2, or A9, or the cell of the order that you are going to generate.

The button is coded so that the order is generated based on the selected cell.

This is the code:

Code:
Sub SimpleMacro()
    Application.ScreenUpdating = False
    Set h1 = Sheets("SourceSheet")  'Source
    Set h2 = Sheets("TargetSheet")  'Target
    If ActiveCell.Column <> 1 Then
        MsgBox "Select cell in column A"
        Exit Sub
    End If
    If Not IsDate(ActiveCell.Value) Then
        MsgBox "Selet cell with date of order"
        Exit Sub
    End If
    fila = ActiveCell.Row
    h1.Range("A" & fila).Copy h2.Range("D5")
    h1.Range("A" & fila + 2).Copy h2.Range("D6")
    h1.Range("C" & fila + 1 & ":C" & fila + 5).Copy h2.Range("B7:B11")
    h1.Range("B" & fila + 1 & ":B" & fila + 5).Copy h2.Range("A7:A11")
    h1.Range("C" & fila).Copy h2.Range("B6")
    h1.Range("E" & fila + 4).Copy
        h2.Range("E5").PasteSpecial xlValues
    Application.CutCopyMode = False
    MsgBox "Invoice Created"
End Sub

New example with the new code:
https://www.dropbox.com/s/hkew9ewvsfk6mre/tes-c4a dam.xlsm?dl=0


Select cell A2 and press button, review sheet target, return to sheet source select cell A9 and press button, review sheet target.

You can create more lines in your sheet source, only select the date of column A and press button to generate de invoice.

Test and tell me.
 
Upvote 0
That is perfect, I can now work on the layouts to make them how I want them.
If I were to add a secondary button would it just be a matter of copying it and editing it perform similar tasks but to output to a "2nd destination sheet"?
 
Upvote 0
That is perfect, I can now work on the layouts to make them how I want them.
If I were to add a secondary button would it just be a matter of copying it and editing it perform similar tasks but to output to a "2nd destination sheet"?

It is correct, in the secondary button you would have to put the new tasks.
 
Upvote 0
Thanks DanteAmor, you have been really helpful and is great for you to spend your time doing this.

On another note, can you advise on how to use excel to perform a stock system, i.e. "x" amount of product "a" on one sheet, when a batch number is put in on another sheet it then deducts - so like a stock control system?
Thanks in advance
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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