Use the same code in use again but for another project

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
6,007
Office Version
  1. 2024
Platform
  1. Windows
I have a code in use which works well & i would like to use it again but for a different task.
Currently this is the code in use supplied below.
It check's that the user has double clicked a customer in column A & if so it opens up a userform.

Now i think i need to use the same again code but with an alteration,

Change column 1 for column 2
Change the A8 to B8 & the A for B BUT im stuck on this new part required.
I dont want it to open a form BUT to copy the value in column B & then paste it to cell F7 on the sheet named MCVIN



Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 Then
   If Intersect(Range("A8", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then Exit Sub
      Cancel = True
      MotorcycleDatabase.LoadData Me, Target.Row
End If
End Sub
 
Just gone to bed but then had a thought.
Would I need to,
Active cell.Copy
Activate MCVIN
Paste in Range mentioned ?
 
Upvote 0
VBA Code:
Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    If Target.Column = 2 Then
        If Intersect(Range("B8", Cells(Rows.Count, "B").End(xlUp)), Target) Is Nothing Then Exit Sub
        Cancel = True
        
        Dim CopyValue As Variant
        CopyValue = Target.Value
        
        With ThisWorkbook.Worksheets("MCVIN")
            .Range("F7").Value = CopyValue
        End With
    
    End If

End Sub
 
Upvote 0
Using that ocde i get RTE 1004 Select method of range failed.

I am then taken to the worksheet change event
 
Upvote 0
Using that ocde i get RTE 1004 Select method of range failed.

I am then taken to the worksheet change event
If you have a Worksheet_Change event on that sheet, it will get called whenever a value on your sheet is updated, when manually or by your other code.
If you do not want it to be called when this code is being run, you need to temporarily disable Event Procedures while that code makes the update, i.e.
Rich (BB code):
        With ThisWorkbook.Worksheets("MCVIN")
            Application.EnableEvents = False
            .Range("F7").Value = CopyValue
            Application.EnableEvents = True
        End With
 
Upvote 0

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