Need to merge two working codes into one

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
6,146
Office Version
  1. 2024
Platform
  1. Windows
I have two codes on my sheet that work fine & now need to merge them & also an additional piece to be added.

Code 1 in use
I double click a customer in column A & a user form opens called MOTORCYCLEDATABASE

Code 2 in use
I select a value in column B then click a command button.
The value that was selected is entered in the cell F7 on a different sheet called MCVIN

I need them combined like so & codes for both are supplied below

The user will double click a customer in column A, example A10
** if another column is clicked show message **

** once the above is confirmed then check if the value to the right in column C is HONDA **
If the value is HONDA then
The code will copy the value in the cell, example B10 & on sheet MCVIN put into cell F7
The user form MOTORCYCLEDATABASE is now opened

If the value ISNT HONDA then just go straight to opening the user form MOTORCYCLEDATABASE,no need to copy value to sheet MCVIN


CODE 1
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


CODE2
Rich (BB code):
Private Sub McVin_Click()
Dim answer As Integer
Dim r As Long
If ActiveCell.Column = 2 Then
   Sheets("MCVIN").Range("F7").Value = ActiveCell.Value
Else
   MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN B", vbCritical, "SELECT CUSTOMER MESSAGE"
End If
Worksheets("MCVIN").Activate
End Sub
 
Ok so here is an updated code that works 99%

The user now has to double click in column B
It is now i need something to be added to the working code below for it to check if the value to the right of the double clicked cell is HONDA
If it is then please allow code to continue.
If its anything else then the code will Exit Sub.
Explanation shown below in RED

Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim answer As Integer
Dim r As Long
If Target.Column = 2 & VALUE TO THE RIGHT IS HONDA Then
   Sheets("MCVIN").Range("F7").Value = ActiveCell.Value
Else
   MsgBox "YOU MUST SELECT A CUSTOMER IN COLUMN B", vbCritical, "SELECT CUSTOMER MESSAGE"
   Exit Sub
End If
   Worksheets("MCVIN").Activate
   Worksheets("MCLIST").Activate
   MotorcycleDatabase.LoadData Me, Target.Row
End Sub
 
Upvote 0
Any help to solve this please
Target column MUST be 2 & Column C MUST be HONDA
The below gives me a syntax error each time

Rich (BB code):
If Target.Column = 2 And Column C =("HONDA") Then
 
Upvote 0
Maybe the below:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim answer As Integer
Dim r As Long
If Target.Column = 2 And Target.Offset(, 1) = "HONDA" Then
   Sheets("MCVIN").Range("F7").Value = ActiveCell.Value
Else
   MsgBox "YOU MUST SELECT A CUSTOMER IN COLUMN B", vbCritical, "SELECT CUSTOMER MESSAGE"
   Exit Sub
End If
   Worksheets("MCVIN").Activate
   Worksheets("MCLIST").Activate
   MotorcycleDatabase.LoadData Me, Target.Row
End Sub
 
Upvote 0
That did work.
Maybe you can advise if i need 2 different Messages to be shown.

One message for YOU MUST SELECT A CUSTOMER IN COLUMN A

&

One for SELECTION MUST BE HONDA

Thanks
Currently the shown message applies for both
 
Upvote 0
You mention that "YOU MUST SELECT A CUSTOMER IN COLUMN A" but you are checking Target.Column = 2.
Do you mean customer in column B?
 
Upvote 0
Maybe this:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Target.Column = 2 Then
        If Target.Offset(, 1) = "HONDA" Then
            Sheets("MCVIN").Range("F7").Value = ActiveCell.Value
        Else
            MsgBox "Column C must be Honda", vbCritical, "Vehicle Make Message"
            Exit Sub
        End If
    Else
        MsgBox "YOU MUST SELECT A CUSTOMER IN COLUMN B", vbCritical, "SELECT CUSTOMER MESSAGE"
        Exit Sub
    End If
    
    Worksheets("MCLIST").Activate
    MotorcycleDatabase.LoadData Me, Target.Row
End Sub
 
Upvote 0
Solution

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