Search : in
By :

Combinate 2 vba codes

Last answer on Jul 4, 2009 5:43:13 am BST mia, on Jul 2, 2009 11:30:15 am BST 
 Report this message to moderators

Hello,
How can I write these to codes into one code?

Code1)

Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim MyRange As Range
Dim IntersectRange As Range

Set MyRange = Range("d9:e38")

Set IntersectRange = Intersect(Target, MyRange)

On Error GoTo SkipIt

If IntersectRange Is Nothing Then
Exit Sub

Else

ActiveSheet.Unprotect
Application.ScreenUpdating = False

Target = Format(Now, "ttttt")

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xllockedCells

End If

ActiveSheet.Unprotect
Rows("1:3").Select
Range("1:3,A4:E65536").Select
Range("1:3,A4:E65536,G4:IV65536").Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False

ActiveCell.Offset(, 1).Select

SkipIt:
Exit Sub


End Sub


Code 2)
Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Const WS_RANGE As String = "A9:A39" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

With Target

Me.Unprotect
Target.Value = Format(Now, "ddddd")
Me.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Me.EnableSelection = xllockedCells
Cancel = True
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

Configuration: Windows 2003 Internet Explorer 6.0

Best answers for « combinate 2 vba codes » in :
Connect a database (MDB) to excel Show [VBA] Connecting a database (MDB) to excel Below is a tips of how to connect an Access database (MDB) in an application excel Add reference Microsoft DAO object librairy X.X In a general module (eg Module1) paste the code below...
Call of duty 2 (COD2) Bugs ShowCall of duty 2 (COD2) Bugs Call of duty 2 bugs on VISTA Patch Installation Direct X 10 configurations Multiplayer Mode You have problems running COD 2 on Vista? This is because this FPS game was released before vista So we will...
Adding a VBA CommandButton with its respective the code ShowAdding a VBA CommandButton with its respective the code Paste these two sub in a general module (Module1 for example). Sub CreateButton() Dim Obj As Object Dim Code As String Sheets("Sheet1").Select 'create button ...
[Philips] updating firmware or codec Show[Philips] updating firmware or codec Intro Method 1 Method 2 Cp-page Content frame Intro Updating Philips firmware or codecs -Home DVD player -PC DVD Writer Philips International website has a new feature included for the...
Download DivX codecs ShowDivx Community is free for personal usage and allows your computer to read files in DivX format! The installer contains the following elements: DivX Player 6.8.2 DivX Community Codec 6.8.4 DivX Web Player 1.4 The installer also contains...
Download Code::Blocks Studio ShowCode:: Blocks is a multi-platform IDE (Linux, Mac and Windows) completely coded in C ++. Code:: Blocks is based on a system of plugins which allows to develop it very easily without recompiling it. Since it supports a great number of compilers, the...
ASCII Code ShowData coding Morse code was the first code used for long-distance communication. Samuel F.B. Morse invented it in 1844. This code is made up of dots and dashes (a sort of binary code). It was used to carry out communication much faster than could...
CMYK (CMJN) Coding ShowCMY Coding CMY Coding (Cyan, Magenta, Yellow) is to subtractive synthesis, what RGB coding is to additive synthesis. This model consists in breaking up a colour into values of Cyan, Magenta and Yellow. The absence of these three components yields...
Huffman coding ShowHuffman coding In 1952, David Huffman proposed a statistical method allowing a binary code word to be assigned to the various symbols to be compressed (pixels or characters for example). The length of each code word is not identical for all the...

1

 Excelguru, on Jul 4, 2009 5:43:13 am BST

Hi mia

Try this


Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Const WS_RANGE As String = "A9:A39"
    Dim MyRange As Range
    Dim IntersectRange As Range
    Set MyRange = Range("d9:e38")
    Set IntersectRange = Intersect(Target, MyRange)
    On Error GoTo SkipIt
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
        With Target
            Me.Unprotect
            Target.Value = Format(Now, "ddddd")
            Me.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
            Me.EnableSelection = xllockedCells
            Cancel = True
        End With
    Else
        If IntersectRange Is Nothing Then
            Exit Sub
        Else
            ActiveSheet.Unprotect
            Application.ScreenUpdating = False
            Target = Format(Now, "ttttt")
            ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
            ActiveSheet.EnableSelection = xllockedCells
        End If
        ActiveSheet.Unprotect
        Rows("1:3").Select
        Range("1:3,A4:E65536").Select
        Range("1:3,A4:E65536,G4:IV65536").Select
        Selection.Locked = False
        Selection.FormulaHidden = False
        ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
        ActiveCell.Offset(, 1).Select
    End If
SkipIt:
    Application.EnableEvents = True
    Exit Sub
End Sub
Winners are losers who got up and gave it one more try. -Dennis DeYoung
My Interests are financial Modelling and custom excel development.

Reply to Excelguru