PDA

View Full Version : automatic calculation



maksinx
02-15-2007, 02:06 PM
hello everyone;

i have below code for auto calculation and i would like to apply same code to entire column.

basicly what i want to is whatever value i write on a2 it should add up to the value on b2 and ,a3 to b3, a4 to b4, a5 to b5,


a1 heading is = last stock quantity
b1 heading is = total stock quantity

and also i would like to use the same logic (code) for stock deduction
lets say i write wtosk value on a2 and deduct that figure from the value of b2.

any help is highly appreciated.

thanks in advance



Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("B2") = ActiveSheet.Range("B2") + ActiveSheet.Range("A2")
Application.EnableEvents = True
End Sub

mdmackillop
02-15-2007, 02:13 PM
Hi Maksinx
Welcome to VBAX
Unfortunately, I can't quite follow your request. Can you post a workbook with a simple example and explanatory notes. You can do this using Mange Attachments in the Go Advanced section.
BTW, if you want to post code, paste it from your VBE, then select it and click the VBA button which will format it for easier reading
Regards
MD

maksinx
02-15-2007, 02:31 PM
hello mdmackillop
i have added the file as request and i would like to explain little bit more.
i have a stock list and first row has got headings such as , invoice no,invoice value, supplier,product description,last stock quantity and total stock quantity.

for example;
a= last stock quantity
b= total stock quantity

i entered in a2 500 it should appear on b2 but when i enter a2 another figure lets say 1500 the value on b2 should change to 2000 to make it simple all the entries in column a should be added to the cell value on b.

a2 will be added b2
a3 will be added b3
a4 will be added b4
.
.
.
.
.
.
if you need further information please let me know.

mdmackillop
02-15-2007, 03:36 PM
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp).Offset(1))) Is Nothing Then
Target.Offset(, 1) = Target.Offset(, 1) + Target
End If
Application.EnableEvents = True
End Sub

Charlize
02-16-2007, 03:40 AM
Private Sub Worksheet_Change(ByVal Target As Range)
If Selection.Count > 1 Then
Exit Sub
ElseIf Target.Row = 1 Then
Exit Sub
Else
If Target.Column = 1 Then
Application.EnableEvents = False
If IsEmpty(Target.Offset(, 1).Value) Then
Target.Offset(, 1).Value = Target.Value
Else
Target.Offset(, 1).Value = Target.Offset(, 1).Value + Target.Value
End If
Application.EnableEvents = True
End If
End If
End Sub