Results 1 to 3 of 3

Thread: Re writing a code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Re writing a code?

    Can some show me how to rewrite code 2 using the instructions and example from the first code. I'm trying to get code 2 to do a on going calculation.


    The first code is a the step by step instructions on using the VBA event macro.
    for doing a ongoing calculation In Excel 2007

    Open the file where this is to be used
    Select the sheet where this is to be used
    Right click the sheet tab
    Select: View Code (this will open the VB editor)
    Copy the code below and paste it into the window that opens on the right hand side of the screen:

    [Select Code] copy to clipboard

    Code:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
              With Target
                 If .Address(False, False) = "BY6" Then
                    If IsNumeric(.Value) Then
                       Application.EnableEvents = False
                       Range("GU").Value = Range("GU3").Value + .Value
                       Application.EnableEvents = True
                    End If
                 End If
              End With
        End Sub

    -------------------------------------------------------------------------------------
    The code above shows how to make BY6 add to GU3 daily when I copy and paste special (value) and
    it works. but when I ex-span the ranges is where I mess up.

    I'm Wanting to make changes to the code below so it will do on going 30 day calculations. can this be done?
    I know my codes below do not work because when I copy and paste special (value) to BY6:DP20
    The target ranges GU3 THRU JJ71 only show the values from BY6:DP20 and do not add to the totals
    already in GU3 thru JJ71.
    How can I change the code below (change something, delete something, add something) to get it to do a on going calculation.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        
        '//if the target range is in anywhere on range "BY6:DP20"
        If Not Intersect(Target, Range("BY6:DP20")) Is Nothing Then
            With Target
                If IsNumeric(.Value) Then
                    Application.EnableEvents = False
                    Range("GU3").Value = Range("HB218").Value + 1
                    Range("HG3").Value = Range("HN218").Value + 1
                    Range("HS3").Value = Range("HZ218").Value + 1
                    Range("IE3").Value = Range("IL181").Value + 1
                    Range("IQ3").Value = Range("IX181").Value + 1
                    Range("JC3").Value = Range("JJ71").Value + 1
    
    Application.EnableEvents = True
                End If
            End With
        End If
        
    End Sub
    I was told to make what I wanted to work,I would have to write the code using Adding an accumulator for multiple cells.
    does anyone know how that is done?
    Last edited by justme1052; 01-22-2014 at 06:24 PM.

Similar Threads

  1. Replies: 1
    Last Post: 08-23-2013, 06:33 PM
  2. Shorten VBA Code By Removing Redundant Superfluous Code
    By paul_pearson in forum Excel Help
    Replies: 2
    Last Post: 08-15-2013, 09:09 PM

Posting Permissions

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