So I have a macro to add a line to a database I've created by copying an existing line and inserting above then clearing the data.
Mostly it works fine, but every once in a while for no reason that I can tell, it will suddenly give me an error. Usually happens when I am running the macro a few times in a row.
I make sure that the macro has finished running before running it again (which freezes it rather than give me an error anyway).
I should also note that this error also freezes Excel (opening the code editor is the only thing that still works) so I have to restart.
Any thoughts?
This is the line that's giving me trouble (or at least it's the one that's highlighted when I hit "Debug")
Selection.Insert Shift:=xlDown
Full code below
Thanks
Mostly it works fine, but every once in a while for no reason that I can tell, it will suddenly give me an error. Usually happens when I am running the macro a few times in a row.
I make sure that the macro has finished running before running it again (which freezes it rather than give me an error anyway).
I should also note that this error also freezes Excel (opening the code editor is the only thing that still works) so I have to restart.
Any thoughts?
This is the line that's giving me trouble (or at least it's the one that's highlighted when I hit "Debug")
Selection.Insert Shift:=xlDown
Full code below
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Value = "Double-Click to Add An Action" Then
ActiveCell.Offset(2, 0).Rows("1:1").EntireRow.Select
Selection.Copy
Selection.Insert Shift:=xlDown
ActiveCell.Range("A1:F1").Select
Selection.ClearContents
ActiveCell.Select
ElseIf Target.Value = "Double-Click to Add an Amendment" Then
ActiveCell.Rows("1:3").EntireRow.Select
Selection.Copy
ActiveCell.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
ActiveCell.Select
ActiveCell.FormulaR1C1 = "Amendment"
ActiveCell.Offset(0, 4).Range("A1").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = "HHS #"
ActiveCell.Offset(0, -4).Range("A1").Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
ActiveCell.Offset(2, 0).Range("A1:E1").Select
Selection.ClearContents
End If
Application.CutCopyMode = False
End Sub
Last edited: