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)

Nr.Denumirea produsuluiTipVolumViscozitatePretul (lei)
TERRA
1Terra sugaring classic400g1220 lei
2Terra sugaring classic400g2220 lei
3Terra sugaring classic400g3220 lei
4Terra sugaring classic400g4220 lei
5Terra sugaring classic400g5220 lei
6Terra sugaring classic400g6220 lei
7Terra sugaring classic700g1340 lei
8Terra sugaring classic700g2340 lei

<tbody>
</tbody>

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

Nr.Denumirea produsuluiTipVolumViscozitatePretul (lei)

<tbody>
</tbody>
Thanks a lot in advance !
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
.
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,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

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