copy on double click in sheet1 and then paste into next available row in sheet2.

Sonican

New Member
Joined
Jun 20, 2016
Messages
13
I am very new to vba, which i why i am asking this, I'm sure to most people on here this is a very simple process, but I just cant get it to work.
So here is what i am trying to do.
In sheet one i have a table. in column A, i have an ID number with leading zeros. what i need to happen is when i double click this number, I need it to copy over into sheet2, keeping the leading zeros and starting at cell a1 and from then on each ID number i double click be pasted into the next cell below.

Thank you so much in advance, i'm so lost its sad :(
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Right click sheet1, VIEW CODE and copy paste this:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim lastrow As Long
If Target.Column = 1 Then
On Error Resume Next
lastrow = 0
lastrow = Sheet2.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Resume Next
Sheet2.Cells(lastrow + 1, 1).NumberFormat = "@"
Sheet2.Cells(lastrow + 1, 1) = Target
End If
End Sub

I didn't build in anything to consider duplicates
 
Upvote 0
Here this one checks for if the user is trying to copy blanks or duplicates:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim lastrow As Long
If Target.Column = 1 Then


'if sheet1 cell is blank
If Trim(Target) = "" Then
Exit Sub
End If


'check for duplicates
If IsError(Application.Match(Target, Sheet2.Range("A:A"), 0)) = False Then
MsgBox Target & " already on " & Sheet2.Name & " tab", vbInformation, "ALERT"
Exit Sub
End If


On Error Resume Next
lastrow = 0
lastrow = Sheet2.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Resume Next
Sheet2.Cells(lastrow + 1, 1).NumberFormat = "@"
Sheet2.Cells(lastrow + 1, 1) = Target
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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