VBA Copy row from one sheet to another

SokoL94

New Member
Joined
Dec 2, 2018
Messages
3
Hello guys,

I am struggling since a couple of days to create a macro (button) that by clicking will copy the row to the table in another sheet.

From this sheet, "Price List (sugaring)" I would need a button for each and every row.
(basically working as a select button, each time pressed, taking the product to the order list in other sheet)

[TABLE="width: 1088"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Nr.[/TD]
[TD="colspan: 6"]Denumirea produsului[/TD]
[TD]Tip[/TD]
[TD]Volum[/TD]
[TD]Viscozitate[/TD]
[TD="colspan: 4"]Pretul (lei)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 14"] TERRA[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]400g[/TD]
[TD]1[/TD]
[TD="colspan: 4"]220 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]2[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]400g[/TD]
[TD]2[/TD]
[TD="colspan: 4"]220 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]3[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]400g[/TD]
[TD]3[/TD]
[TD="colspan: 4"]220 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]4[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]400g[/TD]
[TD]4[/TD]
[TD="colspan: 4"]220 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]5[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]400g[/TD]
[TD]5[/TD]
[TD="colspan: 4"]220 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]6[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]400g[/TD]
[TD]6[/TD]
[TD="colspan: 4"]220 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]7[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]700g[/TD]
[TD]1[/TD]
[TD="colspan: 4"]340 lei[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]8[/TD]
[TD="colspan: 7"]Terra sugaring classic[/TD]
[TD]700g[/TD]
[TD]2[/TD]
[TD="colspan: 4"]340 lei[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

These would be the first positions in the sheet "Price List (sugaring)"

Now I would like to know how to create a VBA that by clicking any of the positions, it will be copied in the first position of the next table in sheet "Calculator", and with every next click, adding the row to the next empty position below

[TABLE="width: 1024"]
<tbody>[TR]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="class: xl66"]Nr.[/TD]
[TD="class: xl65, colspan: 6"]Denumirea produsului[/TD]
[TD="class: xl65"]Tip[/TD]
[TD="class: xl65"]Volum[/TD]
[TD="class: xl65"]Viscozitate[/TD]
[TD="class: xl65, colspan: 4"]Pretul (lei)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="class: xl67"][/TD]
[TD="class: xl78, colspan: 6"][/TD]
[TD="class: xl77"][/TD]
[TD="class: xl68"][/TD]
[TD="class: xl68"][/TD]
[TD="class: xl68, colspan: 4"][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Thanks a lot in advance !
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
.
Code:
Sub cpyPaste()
Dim pstSht As Worksheet
    Dim rng As Range
    Dim txt As String
    
    'On Error Resume Next
    txt = ActiveWindow.RangeSelection.Address
    Set rng = Selection                   'Copy from
    If rng Is Nothing Then Exit Sub
    Set pstSht = Worksheets("Calculator")     'Paste to
    
    Application.ScreenUpdating = False
    rng.Copy
    pstSht.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    GetSum
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub


Sub GetSum()
'Dim lastrow As Range
lastrow = ThisWorkbook.Sheets("Calculator").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Sheets("Calculator").Range("e" & lastrow + 1) = "Total:"
ThisWorkbook.Sheets("Calculator").Range("f" & lastrow + 1) = Application.WorksheetFunction.Sum(ThisWorkbook.Sheets("Calculator").Range("f2:f" & lastrow))
ThisWorkbook.Sheets("Calculator").Range("f" & lastrow + 1).Font.Bold = True
End Sub

Download workbook : https://www.amazon.com/clouddrive/share/bb7iGzuBZJdVFi9TOZ5ss8LCt8RIyFvvmRtvKY0uv8H
 
Upvote 0
Hello guys,

I am struggling since a couple of days to create a macro (button) that by clicking will copy the row to the table in another sheet.

From this sheet, "Price List (sugaring)" I would need a button for each and every row.
(basically working as a select button, each time pressed, taking the product to the order list in other sheet)
!
Do you mean you have many buttons? so each row of your data set has one button?
 
Upvote 0
Do you mean you have many buttons? so each row of your data set has one button?

Yeap, that's right Akuini. I am going to have one button for each row.
I have already somehow solved the problem with a simple code.

The strugle now is a bit more complicated (I guess)

I would need a code (button), in the Sheet "Calculator", which will restore the table to it's initial, original form.
(with this I mean, after selecting for example a set of products from "product list" which would be copied in the table in "Calculator" sheet, I will need a button which will empty the table and set it to to the original form (background color let's say))
 
Upvote 0
.
Place button on Sheet Caluculator :

Code:
Sub clrAll()
    Sheets("Calculator").Range("A2:F100").Value = ""
End Sub
 
Upvote 0
Yeap, that's right Akuini. I am going to have one button for each row.
I have already somehow solved the problem with a simple code.

The strugle now is a bit more complicated (I guess)

I would need a code (button), in the Sheet "Calculator", which will restore the table to it's initial, original form.
(with this I mean, after selecting for example a set of products from "product list" which would be copied in the table in "Calculator" sheet, I will need a button which will empty the table and set it to to the original form (background color let's say))

If your code copy-paste values only then the table format in "Calculator" sheet won't change, so you don't need to set it to the original format.
As for clearing the data, you can use Logit's code above.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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