Results 1 to 6 of 6

Combine 2 subs

Threaded View

  1. #1
    Registered User
    Join Date
    08-09-2011
    Location
    SC,USA
    MS-Off Ver
    Office2003 & Office2007
    Posts
    8

    Combine 2 subs

    Hello all,
    Totally new to VBA.Found 2 subs that do what i need, but how do i combine them to work on same sheet? One sub will accumulate a cell by using 2 cells. The second sub automatically adds the date when ever i change the accumulating cell.

    Example: I am using 4 columns A,B,C,D

    Column A (Names)
    Column B (Date)
    Column C (Daily Entry)
    Column D (Total)

    C & D are the accumulating and when ever i change a cell in column C the cell in column D will accumulate and the cell in column B will update the date.
    Make sense?

    Here is first sub...
       Private Sub Worksheet_Change(ByVal Target As Excel.Range)
          With Target
             If .Address(False, False) = "A1" Then
                If IsNumeric(.Value) Then
                   Application.EnableEvents = False
                   Range("B1").Value = Range("B1").Value + .Value
                   Application.EnableEvents = True
                End If
             End If
          End With
        End Sub
    Here is second sub...

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Then Exit Sub
    
            If Not Intersect(Target, Range("A2:A100")) Is Nothing Then
    
                With Target(1, 2)
    
                    .Value = Date
    
                    .EntireColumn.AutoFit
    
                End With
    
            End If
    
    End Sub
    I really dont know much at all about subs, i just searched out and found these already made, but have no clue as how to combine them.

    Any help is much appreciated.
    Thanks,

    Troy
    Last edited by tday7; 10-07-2011 at 05:02 PM.

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