Help... VBA Code to copy and paste value in a new sheet in last row

santhoshlk

Board Regular
Joined
Feb 6, 2006
Messages
206
Dear Friends.

Pls help me to develop my below macro.
I have a workbook with 2 sheets, say "Entry" and "List"
"Entry" sheet has the following cells B6 and D7.
What I need is a command button in Entry Sheet, once I enter any data in B6
and D7 and if I click the command button macro should copy the cell "Entry(B6)" and paste value in cell "List(A1)' also copy cell "Entry(D7)" and paste value in cell "List(B2)".
a msg box to be appear and say "Your entry has updated" and the sheet "Entry" to be active and cells are cleared for the next new entry.

IMPORTANT is whenever I update the entry by clicking the command, the data should be copied in sheet "List" in next row so I keep the entry records in that sheet.

Please help.

Thanks in advance. S
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this:

Code:
Sub Paste_My_Data()
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("list").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowa = Sheets("List").Cells(Rows.Count, "B").End(xlUp).Row + 1
Sheets("List").Range("A" & Lastrow).Value = Sheets("Entry").Range("B6").Value
Sheets("List").Range("B" & Lastrowa).Value = Sheets("Entry").Range("D7").Value
Sheets("Entry").Range("B6").ClearContents
Sheets("Entry").Range("D7").ClearContents
MsgBox "Your entry has updated"
End Sub
 
Upvote 0
Try this:

Code:
Sub Paste_My_Data()
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("list").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowa = Sheets("List").Cells(Rows.Count, "B").End(xlUp).Row + 1
Sheets("List").Range("A" & Lastrow).Value = Sheets("Entry").Range("B6").Value
Sheets("List").Range("B" & Lastrowa).Value = Sheets("Entry").Range("D7").Value
Sheets("Entry").Range("B6").ClearContents
Sheets("Entry").Range("D7").ClearContents
MsgBox "Your entry has updated"
End Sub

Wow... It works perfectly... thanks a lot Bro
 
Upvote 0
Dears,

Can you pls help in below code:

Sheets("Form").Range("B8").ClearContents

here I need to clear the contents of sheet "form" cell A21 as wel.

Thanks
 
Upvote 0
Try this:

You should try reading the code and in time you should understand how to make additions and changes yourself.

You should see here I just added one more line of code.

I want in the long run to:
"Teach You To Fish" and not just give you a "Fish".



Code:
Sub Paste_My_Data()
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("list").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowa = Sheets("List").Cells(Rows.Count, "B").End(xlUp).Row + 1
Sheets("List").Range("A" & Lastrow).Value = Sheets("Entry").Range("B6").Value
Sheets("List").Range("B" & Lastrowa).Value = Sheets("Entry").Range("D7").Value
Sheets("Entry").Range("B6").ClearContents
Sheets("Entry").Range("D7").ClearContents
Sheets("Entry").Range("A21").ClearContents
MsgBox "Your entry has updated"
End Sub
 
Last edited:
Upvote 0
What's not working?

You said in post #3

Wow... It works perfectly... thanks a lot Bro
 
Upvote 0
Yes... Its working correctly.

The prob is when I aply the clear content code for cell A21, which is merged.
Is there any solution to clear the content in merged cells

Thanks in advance
 
Upvote 0
What cell is in the upper left corner of the Merged cells?
Change the script to refer to the cell in the upper left corner of the Merged cells.

We constantly tell people to not use merged cells they can cause you a lot of headaches.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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