ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Creating a code for a macro (https://www.excelbanter.com/excel-discussion-misc-queries/186971-creating-code-macro.html)

engbe

Creating a code for a macro
 
Hi, Can any one please help me with writing a code in visual basics?

What i am trying to do is this:
I want to create a button called 'close' in row 1(sheet 1) and when I click
this I want a marco to run which will delete the entire row that the button
is on and then paste that row into row 5 in worksheet 2. I want to repeat
this for the next row however, when the second row is pasted into worksheet 2
i want the second row to be pasted in row 5 and the first row move down to
row 6...

I hope this makes sense and would really appreciate any assistance from
anyone as i am not to familiar with writing up codes...THANK YOU in advance!

Don Guillett

Creating a code for a macro
 
One way. Use ONLY one button and select the row first.

Sub movelastrowtoothersheet()
With Sheets("sheet2")
dlr = .Cells(Rows.Count, "a").End(xlUp).Row + 1
'MsgBox dlr
slr = ActiveCell.Row
'if you always want it to be the LAST row use this line instead
'slr = Cells(Rows.Count, "a").End(xlUp).Row
'MsgBox slr
Rows(slr).Copy .Cells(dlr, "a")
Rows(slr).Delete
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"engbe" wrote in message
...
Hi, Can any one please help me with writing a code in visual basics?

What i am trying to do is this:
I want to create a button called 'close' in row 1(sheet 1) and when I
click
this I want a marco to run which will delete the entire row that the
button
is on and then paste that row into row 5 in worksheet 2. I want to repeat
this for the next row however, when the second row is pasted into
worksheet 2
i want the second row to be pasted in row 5 and the first row move down to
row 6...

I hope this makes sense and would really appreciate any assistance from
anyone as i am not to familiar with writing up codes...THANK YOU in
advance!




All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com