VBA code stop working

Panda120

New Member
Joined
May 16, 2018
Messages
5
I wanted to use the same layout for two projects, and was to lazy to create an entire new worksheet, so I made a copied of the worksheet's whose format and VBA codes I wanted to use. Apart from the colour scheme, I've made no changes to the copied document. The VBA code still works in the original document, but not in the copied document. I've also check, and the VBA codes are still exactly the same. Any suggestions as to why it just suddenly stopped working? I have on prior occasions made copies of other documents with VBA codes, and the codes still ran in the copied version.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Do you get any error messages when you run the code?
if so what & where?
Also it would help if you could post one of the macros that doesn't work.
 
Upvote 0
No, it doesn't throw out any error messages. Here is the code:

Code:
Option Explicit




Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim strCellVal As String
Dim i As Long


    On Error Resume Next
    
    If Intersect(Target.EntireRow, [Projects[Project]]) Is Nothing Then Exit Sub
    If Target.Cells.Count <> 1 Then Exit Sub
    
    strCellVal = ActiveCell.Value
    
    With Sheet2
        .ListObjects(1).Range.AutoFilter 3, Criteria1:=Intersect(Target.EntireRow, [Projects[Project]])
        .Activate
        i = .ListObjects(1).Range.Columns(1).SpecialCells(xlCellTypeVisible).Count
     If i = 1 Then
        .ListObjects(1).Range.End(xlDown).Offset(1, 2).Value = strCellVal
     End If
        .[A1].Select
    End With
        
    Cancel = True


End Sub


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Developed by Contextures Inc.
' [URL="http://www.contextures.com"]www.contextures.com[/URL]
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler


On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler


If rngDV Is Nothing Then GoTo exitHandler


If Intersect(Target, rngDV) Is Nothing Then
   'do nothing
Else
  Application.EnableEvents = False
  newVal = Target.Value
  Application.Undo
  oldVal = Target.Value
  Target.Value = newVal
  If Target.Column = 5 Then
    If oldVal = "" Then
      'do nothing
      Else
      If newVal = "" Then
      'do nothing
      Else
      Target.Value = oldVal _
        & ", " & newVal
'      NOTE: you can use a line break,
'      instead of a comma
'      Target.Value = oldVal _
'        & Chr(10) & newVal
      End If
    End If
  End If
End If


exitHandler:
  Application.EnableEvents = True
End Sub

It is suppose to take me to the a selected task when I double click on a specific cell, but all that happens is that it opens the cell for editing
 
Last edited by a moderator:
Upvote 0
Remove this line
Code:
On Error Resume Next
What happens?
 
Upvote 0
.
Did you paste the macro into the SHEET LEVEL MODULE or a ROUTINE MODULE ?

It belongs in the SHEET LEVEL MODULE.

Right click the tab of the sheet you want the macro to work on. Select VIEW CODE.

Paste the macro in the SHEET LEVEL MODULE and try the macro again.
 
Upvote 0
Add the line in red as shown
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   Dim strCellVal As String
   Dim i As Long
   [COLOR=#ff0000]Stop[/COLOR]
   If Intersect(Target.EntireRow, [Projects[Project]]) Is Nothing Then Exit Sub
Then double click in the relevant column. Does that line of code get highlighted?
 
Upvote 0
Firstly run this
Code:
Sub chk()
Application.EnableEvents = True
End Sub
then try double clicking in the Projects columns. If that doesn't help you have the code in the wrong place.
Right click on the tab you want the code to work on > view code. Your code should be in the window that opens up.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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