Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Impossible with formula BUT

Hi All!
This is my delema:
A1 contains a number (say 3)
Following is what I am trying to achieve:
A2 reflects A1 BUT when A1 is changed to 2, then A2 must Show the total of
A1 before(3) + A1 now(2) so A2 must show 5.
I tried using another row to enter the new data but no joy.
May be someone can help me with a macro that when A1 is clicked (to enter
the new value) the old value is stored in a variable and passed on to A2
for adding up.
I hope I made myself understood.
Thanks
Regards
bahri


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Impossible with formula BUT

Hello,

Put this code in the skeet code:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not (Application.Intersect(Range("A1"), Target) Is Nothing) Then
Range("A2").Value = Range("A2").Value + Range("A1").Value
End If
Application.EnableEvents = True
End Sub

hope it will help you

"bahri" a écrit dans le message de
...
Hi All!
This is my delema:
A1 contains a number (say 3)
Following is what I am trying to achieve:
A2 reflects A1 BUT when A1 is changed to 2, then A2 must Show the total of
A1 before(3) + A1 now(2) so A2 must show 5.
I tried using another row to enter the new data but no joy.
May be someone can help me with a macro that when A1 is clicked (to enter
the new value) the old value is stored in a variable and passed on to A2
for adding up.
I hope I made myself understood.
Thanks
Regards
bahri


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Impossible with formula BUT

You could turn calculation to manual (and use a circular reference), but that
always scares me.

Instead, you could use an event macro like the one JE McGimpsey shares:
http://mcgimpsey.com/excel/accumulator.html

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

bahri wrote:

Hi All!
This is my delema:
A1 contains a number (say 3)
Following is what I am trying to achieve:
A2 reflects A1 BUT when A1 is changed to 2, then A2 must Show the total of
A1 before(3) + A1 now(2) so A2 must show 5.
I tried using another row to enter the new data but no joy.
May be someone can help me with a macro that when A1 is clicked (to enter
the new value) the old value is stored in a variable and passed on to A2
for adding up.
I hope I made myself understood.
Thanks
Regards
bahri


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Impossible with formula BUT

Hi All!
Have not tried anything yet I just saw the quick response, seems OK.
I Cannot Thank you all enough. Great!!

Regards
bahri
=================

"Dave Peterson" wrote in message
...
You could turn calculation to manual (and use a circular reference), but
that
always scares me.

Instead, you could use an event macro like the one JE McGimpsey shares:
http://mcgimpsey.com/excel/accumulator.html

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

bahri wrote:

Hi All!
This is my delema:
A1 contains a number (say 3)
Following is what I am trying to achieve:
A2 reflects A1 BUT when A1 is changed to 2, then A2 must Show the total
of
A1 before(3) + A1 now(2) so A2 must show 5.
I tried using another row to enter the new data but no joy.
May be someone can help me with a macro that when A1 is clicked (to enter
the new value) the old value is stored in a variable and passed on to A2
for adding up.
I hope I made myself understood.
Thanks
Regards
bahri


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Impossible with formula BUT

Hi
I have tried a few things out.
Works great on one instance that is applied to one row and combining for two
rows as below for rows 1 and 2:
==================
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

With Target
If .Address(False, False) = "A2" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("B2").Value = Range("B2").Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub
=====================
However is there a way to apply the macro for several rows without producing
such long code?
Thanks all

Regards
bahri




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Impossible with formula BUT

So you're putting the accumulator in column B (not in the row below), right?

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Cells.Count 1 Then
Exit Sub 'one cell at a time!
End If

'change the range to check here
If Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
Exit Sub
End If

With Target
If IsNumeric(.Value) Then
If IsNumeric(.Offset(0, 1).Value) Then
Application.EnableEvents = False
.Offset(0, 1).Value = .Offset(0, 1).Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

bahri wrote:

Hi
I have tried a few things out.
Works great on one instance that is applied to one row and combining for two
rows as below for rows 1 and 2:
==================
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

With Target
If .Address(False, False) = "A2" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("B2").Value = Range("B2").Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub
=====================
However is there a way to apply the macro for several rows without producing
such long code?
Thanks all

Regards
bahri


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Impossible with formula BUT

Hi!
That works Great
Thanks

Regs
bahri
"Dave Peterson" wrote in message
...
So you're putting the accumulator in column B (not in the row below),
right?

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Cells.Count 1 Then
Exit Sub 'one cell at a time!
End If

'change the range to check here
If Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
Exit Sub
End If

With Target
If IsNumeric(.Value) Then
If IsNumeric(.Offset(0, 1).Value) Then
Application.EnableEvents = False
.Offset(0, 1).Value = .Offset(0, 1).Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

bahri wrote:

Hi
I have tried a few things out.
Works great on one instance that is applied to one row and combining for
two
rows as below for rows 1 and 2:
==================
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

With Target
If .Address(False, False) = "A2" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("B2").Value = Range("B2").Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub
=====================
However is there a way to apply the macro for several rows without
producing
such long code?
Thanks all

Regards
bahri


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Impossible Formula sed Excel Discussion (Misc queries) 7 June 16th 08 09:24 PM
impossible formula sed Excel Discussion (Misc queries) 1 June 12th 08 09:00 PM
Impossible Formula! Filmmaker Excel Worksheet Functions 2 November 10th 04 03:48 PM
Impossible Formula! Filmmaker Excel Worksheet Functions 1 November 9th 04 10:13 PM
Impossible Formula! Filmmaker Excel Worksheet Functions 5 November 9th 04 07:59 PM


All times are GMT +1. The time now is 04:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"