Macro code to overwrite existing row

cowsbark

New Member
Joined
May 29, 2013
Messages
3
I am trying to build a form to submit data to a second worksheet (basically a database) but would like to be able to recall existing entries to update. I cannot figure out how to overwrite an entry with a given field.

So sheet1 has 12 cells and sheet2 will have 20-30 entries, each row having 12 columns. The first cell is a person's name, and the rest are subject to change, and I would like to be able to search for the entry by name and overwrite the existing data. Below is the macro I am using to copy and paste. Any thoughts?

Sub Test()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim r1 As Range, r2 As Range
Set sh1 = Worksheets("LT Input")
Set sh2 = Worksheets("LT Data")
Set r1 = sh1.Range("E2:E12")
Set r2 = sh2.Cells(Rows.Count, 1).End(xlUp)(2)
r1.Copy
r2.PasteSpecial Transpose:=True
Application.CutCopyMode = False
r1.ClearContents
End Sub

Thanks in advance.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,217,364
Messages
6,136,117
Members
449,993
Latest member
Sphere2215

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