Results 1 to 4 of 4

Code running multiple times. Need to run only once.

Threaded View

  1. #1
    Registered User
    Join Date
    08-20-2007
    Posts
    27

    Code running multiple times. Need to run only once.

    I have the following code which is intended to copy a column of cells and paste them up one position, triggered by a cell val. The problem is the code runs multiple times and performs the copy and paste multiple times. I have tried to insert a 1 second pause in the code to give time for the trigger cell to return to false, but it does not seem to work.

    Private Sub Worksheet_Calculate()
    
      Dim Inrange As Range
      Dim rng As Range
      Set Inrange = Range("D104")
      For Each rng In Inrange.Cells
        If Not IsError(rng.Value) Then
           If Me.Range("D104").Value = "1" Then
            ' NI_LOG Macro
            Range("C3:C102").Select
            Range("C102").Activate
            Selection.Copy
            Range("C2").Select
            ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
            IconFileName:=False
            'Wait 1 second for to avoid multiple logging
            newHour = Hour(Now())
            newMinute = Minute(Now())
            newSecond = Second(Now()) + 1
            waitTime = TimeSerial(newHour, newMinute, newSecond)
            Application.Wait waitTime
           Else
             If Me.Range("D104").Value = "2" Then
             ' PE_Log Macro
             Range("F3:F102").Select
             Range("F102").Activate
             Selection.Copy
             Range("F2").Select
             ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
             IconFileName:=False
             'Wait 1 second for to avoid multiple logging
             newHour = Hour(Now())
             newMinute = Minute(Now())
             newSecond = Second(Now()) + 1
             waitTime = TimeSerial(newHour, newMinute, newSecond)
             Application.Wait waitTime
             End If
           End If
        End If
      Next rng
    
    End Sub
    Last edited by tmkkoservo; 10-10-2014 at 09:38 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Running the same command multiple times
    By mej in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-11-2013, 12:03 AM
  2. Macro for running the SQL code multiple times
    By sawoodalam1989 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2013, 08:35 PM
  3. Macro for running the SQL multiple times
    By sawoodalam1989 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2013, 07:00 AM
  4. help fixing my macro from running multiple times
    By MurseBry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2010, 02:17 AM
  5. running loop multiple times?
    By mister tom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2010, 01:43 PM

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