+ Reply to Thread
Results 1 to 3 of 3

More than one visual basic code

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2007
    Posts
    7

    More than one visual basic code

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Value = "" Then
            Exit Sub
        Else
            Sheets("Sheet1").Unprotect Password:="bob"
            Target.Locked = True
            Sheets("Sheet1").Protect Password:="bob"
        End If
    End Sub
        Private Sub Worksheet_Change(ByVal Target As Excel.Range)
            With Target
                If .Count > 1 Then Exit Sub
                If Not Intersect(Range("A2:A750"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, -1).ClearContents
                    Else
                        With .Offset(0, -1)
                            .NumberFormat = "ddd. dd mmm yy hh.mm"
                            .Value = Now
                        End With
                    End If
                    Application.EnableEvents = True
                End If
            End With
        End Sub
    Sorry to keep making threads, but where do I put these two pieces of code so that they run smoothly alongside each other. The first code is so that only blank cells can be edited.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Just a thought, Why don't you make the cell protect as a deactivate event

    Private Sub Worksheet_Deactivate()
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    06-13-2007
    Posts
    7
    Could someone give me a step-by-step on what to click and so on, because I'm not at all sure how to use visual basic. The worksheet_deactivate doesn't appear to be working.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1