+ Reply to Thread
Results 1 to 2 of 2

Using VBA to change one cell if another one does...?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-28-2004
    Location
    Puyallup, WA
    Posts
    16

    Using VBA to change one cell if another one does...?

    I am working on a scheduler that will, if a shift is entered in one column, first check if there is an employee listed on that row...if no employee is on that row, the entry will be deleted (with an accompanying MsgBox alert)..

    My code does what it is supposed to, but loops forever!

    Private Sub Worksheet_Change(By Val Target As Excel.Range)
    Dim VRange As Range
    Set VRange = Range("B6:B14") 'This is column for start of shift
    If Not Intersect(Target, VRange) Is Nothing Then
    If Target.Offset(0,-1) = "" Then 'Check employee name column...
    MsgBox"There is no employee for that shift...entry deleted"
    Target = "" 'Erase entry in shift column
    End If
    End If
    End Sub


    Any ideas?...I must use VBA for this BTW

    Thanks, Dave

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Well since your existing code changes your worksheet the Change event will get triggered by it, hence the loop.

    You need to turn events off.
    Application.EnableEvents = False
    Then run the code and switch them back on.
    Application.EnableEvents = True

+ 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