Advertisement

05.22.2008 at 08:34AM PDT, ID: 23424813
[x]
Attachment Details

VBA Calculation to add two Columns together

Asked by PrimusPilus in Microsoft Excel Spreadsheet Software, Spreadsheet Software, VB Script

Tags: , ,

Hi there,

I'm looking for some VBA code to help me add two cells in two columns together which look like this:

Current Week Hours | Total Week Hours
4                               |   10
8                               |   14
9                               |   13
9                               |   18
6                               |   19

What happens is the user enters the data in current week hours and it should update total with the correct addition. Meaning for row 1, when I enter 4 in Current , Total should then be updated to 14. I tried with Excel and got nowhere (circular blah blah blah).

There are about 70 rows that have this so it needs to be a loop, and there are some empty cells in both columns which can be safely ignored.

I've been trying to copy and paste pieces of vb code together to try and reach my end goal, I just started with excel and vb this week so I'm completely noob!
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Private Sub SumVis(ByVal Target As Range, Target1 As Range)
    Dim Total As Range
    Dim Current As Range
    Dim TTotal As Integer
    
    Set Current = Intersect([K8:K70], Target)
    Set Total = Intersect([L8:L70], Target1)
    
    'If Current Is Nothing Then Exit Sub
    
    Application.Volatile True 'Everytime a cell changes a calculation is made
    For Each cel In Current.Cells
        If cel = "" Then
           
        Else
            TTotal = cel + cel.Offset(0, 1)
            Cells(Target1.Row, "L") = TTotal
            SumVis = TTotal
        End If
    Next
     
End Sub
[+][-]05.22.2008 at 08:41AM PDT, ID: 21624836

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, Spreadsheet Software, VB Script
Tags: Microsoft, Excel, 2000
Sign Up Now!
Solution Provided By: WJReid
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.22.2008 at 08:50AM PDT, ID: 21624939

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 09:45AM PDT, ID: 21625487

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 09:50AM PDT, ID: 21625531

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628