Help with IF statement in VBA

Shooter_99999

New Member
Joined
Sep 29, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Looking for some help with IF statements.

The below is an extract of a Pivot Table report (column D is normally hidden).

If the user double clicks on an entry in column A, it calls a macro (DTB) that runs another report to provide a detailed breakdown of the number clicked on.


1669903653196.png



The above uses the following code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True ' prevent double-click from causing Edit Mode in cell
If ActiveCell.Offset(, 3).Value = "1" Then Call DTB Else MsgBox ("You need to double click on the Actuals (Inc PO's) Column")
End Sub

I'd like to add similar functionality that if somone clicks on an entry in column C, it will call another Macro, that will provide a breakdown of the figure clicked on.


I can see how I could do this without having the message box, but cannot figure how to do it with keeping the message box.

Thanks in advance
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try:

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Cancel = True ' prevent double-click from causing Edit Mode in cell
  If Not Intersect(Target, Range("A:A, C:C")) Is Nothing Then
    If Range("D" & Target.Row).Value = "1" Then
      If Target.Column = 1 Then
        Call DTB
      Else
        Call anotherMacro
      End If
    Else
      MsgBox ("You need to double click on the Actuals (Inc PO's) Column")
    End If
  End If
End Sub
 
Upvote 0
@DanteAmor

Thanks for the reply, its appreciated.

It calls the 2 separate macros, which is great, however If I click on any other cell, it doesnt display the MsgBox.

Any ideas?
 
Upvote 0
Try:

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Cancel = True ' prevent double-click from causing Edit Mode in cell
  If Not Intersect(Target, Range("A:A, C:C")) Is Nothing Then
    If Range("D" & Target.Row).Value = "1" Then
      If Target.Column = 1 Then
        Call DBT
      Else
        Call anotherMacro
      End If
    Else
      MsgBox "There is no 1 in column D"
    End If
  Else
    MsgBox ("You need to double click on the Actuals (Inc PO's) Column")
  End If
End Sub
 
Upvote 0
@DanteAmor or some other clever fellow, can you provide more assistance please?

The above works superbly, but I now need to add another condition in that when the user clicks on column B, another macro is called.

I've had a go at it, but failed miserably :(


Any help, greatly appreciated.
 
Upvote 0
Try this:

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Cancel = True ' prevent double-click from causing Edit Mode in cell
  If Not Intersect(Target, Range("A:C")) Is Nothing Then
    If Range("D" & Target.Row).Value = "1" Then
      Select Case Target.Column
        Case 1: Call DBT          'column A
        Case 2: Call other        'column B
        Case 3: Call anotherMacro 'column C
      End Select
    Else
      MsgBox "There is no 1 in column D"
    End If
  Else
    MsgBox ("You need to double click on the Actuals (Inc PO's) Column")
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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