Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Help with code for two cell accumulator

I have the following code:

Private Sub Worksheet_Change(ByVal Target As
Excel.Range)
With Target
If .Address(False, False) = "B1" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("C1").Value = Range("C1").Value
+ .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

This is a two cell accumulator that works for ONE row. I
would like to modify it to work for ALL rows in a
worksheet. Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Help with code for two cell accumulator

One way:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

With Target
If .Cells.Count 1 Then
Exit Sub
End If
If .Column = 2 Then
If IsNumeric(.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

ToddG wrote:

I have the following code:

Private Sub Worksheet_Change(ByVal Target As
Excel.Range)
With Target
If .Address(False, False) = "B1" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("C1").Value = Range("C1").Value
+ .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

This is a two cell accumulator that works for ONE row. I
would like to modify it to work for ALL rows in a
worksheet. Any help would be appreciated.


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Help with code for two cell accumulator

That did it...Thanks much Dave
-----Original Message-----
One way:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

With Target
If .Cells.Count 1 Then
Exit Sub
End If
If .Column = 2 Then
If IsNumeric(.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

ToddG wrote:

I have the following code:

Private Sub Worksheet_Change(ByVal Target As
Excel.Range)
With Target
If .Address(False, False) = "B1" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("C1").Value = Range

("C1").Value
+ .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

This is a two cell accumulator that works for ONE row. I
would like to modify it to work for ALL rows in a
worksheet. Any help would be appreciated.


--

Dave Peterson

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Help with code for two cell accumulator

"ToddG" wrote in message ...
I have the following code:

Private Sub Worksheet_Change(ByVal Target As
Excel.Range)
With Target
If .Address(False, False) = "B1" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("C1").Value = Range("C1").Value
+ .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

This is a two cell accumulator that works for ONE row. I
would like to modify it to work for ALL rows in a
worksheet. Any help would be appreciated.



Hi!
Maybe this is what you are looking for:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If IsNumeric(.Value) Then
Application.EnableEvents = False

.Offset(, 1).Value = .Offset(, 1).Value + .Value

Application.EnableEvents = True
End If
End With
End Sub

I have changed your cell accumulator, so that the values of the target
cell are added up in the cell right to the target cell(row offet =1).

Michi
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
Accumulator BadBoy Excel Worksheet Functions 2 April 24th 09 12:25 PM
accumulator with other than one dan Excel Worksheet Functions 8 November 24th 06 06:29 PM
Need help with two cell accumulator dlashley Excel Worksheet Functions 1 May 12th 06 11:02 AM
Two cell accumulator Bill Excel Worksheet Functions 4 August 21st 05 09:07 PM
Two cell accumulator Bill Excel Worksheet Functions 1 January 3rd 05 03:15 PM


All times are GMT +1. The time now is 11:11 AM.

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

About Us

"It's about Microsoft Excel"