Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Please help fix my accumulator

I've read everything in this group about accumulators, and have
cobbled together some code. I'm puzzled why it won't work. I'm just
looking for a summary worksheet to capture daily journal entries
into a monthly entry, like so:

ClosingEntry SummaryClosingEntry

Cash Cash
CreditCard1 CreditCard1
CreditCard2 CreditCard2
Etc. Etc.

One workbook, two worksheets, code is in the ClosingEntry worksheet
module. Thanks for your help, in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address(False, False, , False) =
Worksheets("ClosingEntry").Range("C5") Then
If IsNumeric(.Value) Then
Application.EnableEvents = False

Worksheets("SummaryClosingEntry").Range("C5").Valu e = _
Worksheets("ClosingEntry").Range("C5").Value +
..Value
Application.EnableEvents = True
End If
End If
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Please help fix my accumulator

One reason is that you're comparing a string (.Address) to a cell value
(.Range("C5")).

I can't tell from your example whether you're trying to implement a
one-cell accumulator or a two-cell accumulator. You only have one cell
reference (C5), but you're not using a static or global variable to
retain the initial value, as is required with a single-cell accumulator.

You might take a look at

http://www.mcgimpsey.com/excel/accumulator.html


Note that you don't have to qualify the ranges when your code is in the
same worksheet as the reference, i.e., in the ClosingEntry worksheet
module,

Worksheets("ClosingEntry").Range("C5")

and

Range("C5")

are equivalent to

Me.Range("C5")

(it doesn't hurt anything, though).

In article ,
Tim McMahon wrote:

I've read everything in this group about accumulators, and have
cobbled together some code. I'm puzzled why it won't work. I'm just
looking for a summary worksheet to capture daily journal entries
into a monthly entry, like so:

ClosingEntry SummaryClosingEntry

Cash Cash
CreditCard1 CreditCard1
CreditCard2 CreditCard2
Etc. Etc.

One workbook, two worksheets, code is in the ClosingEntry worksheet
module. Thanks for your help, in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address(False, False, , False) =
Worksheets("ClosingEntry").Range("C5") Then
If IsNumeric(.Value) Then
Application.EnableEvents = False

Worksheets("SummaryClosingEntry").Range("C5").Valu e = _
Worksheets("ClosingEntry").Range("C5").Value +
.Value
Application.EnableEvents = True
End If
End If
End With

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Please help fix my accumulator

Tim,

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
Dim shSummary As Worksheet

Set shSummary = Worksheets("SummaryClosingEntry")
With Target
If .Address(False, False, , False) = "C5" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
shSummary.Range("C5").Value = _
shSummary.Range("C5").Value + .Value
Application.EnableEvents = True
End If
End If
End With

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tim McMahon" wrote in message
...
I've read everything in this group about accumulators, and have
cobbled together some code. I'm puzzled why it won't work. I'm just
looking for a summary worksheet to capture daily journal entries
into a monthly entry, like so:

ClosingEntry SummaryClosingEntry

Cash Cash
CreditCard1 CreditCard1
CreditCard2 CreditCard2
Etc. Etc.

One workbook, two worksheets, code is in the ClosingEntry worksheet
module. Thanks for your help, in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address(False, False, , False) =
Worksheets("ClosingEntry").Range("C5") Then
If IsNumeric(.Value) Then
Application.EnableEvents = False

Worksheets("SummaryClosingEntry").Range("C5").Valu e = _
Worksheets("ClosingEntry").Range("C5").Value +
.Value
Application.EnableEvents = True
End If
End If
End With

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Please help fix my accumulator

Oops, I missed your call to SummaryClosingEntry. Here's one way:

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




In article ,
JE McGimpsey wrote:

One reason is that you're comparing a string (.Address) to a cell value
(.Range("C5")).

I can't tell from your example whether you're trying to implement a
one-cell accumulator or a two-cell accumulator. You only have one cell
reference (C5), but you're not using a static or global variable to
retain the initial value, as is required with a single-cell accumulator.

You might take a look at

http://www.mcgimpsey.com/excel/accumulator.html


Note that you don't have to qualify the ranges when your code is in the
same worksheet as the reference, i.e., in the ClosingEntry worksheet
module,

Worksheets("ClosingEntry").Range("C5")

and

Range("C5")

are equivalent to

Me.Range("C5")

(it doesn't hurt anything, though).

In article ,
Tim McMahon wrote:

I've read everything in this group about accumulators, and have
cobbled together some code. I'm puzzled why it won't work. I'm just
looking for a summary worksheet to capture daily journal entries
into a monthly entry, like so:

ClosingEntry SummaryClosingEntry

Cash Cash
CreditCard1 CreditCard1
CreditCard2 CreditCard2
Etc. Etc.

One workbook, two worksheets, code is in the ClosingEntry worksheet
module. Thanks for your help, in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address(False, False, , False) =
Worksheets("ClosingEntry").Range("C5") Then
If IsNumeric(.Value) Then
Application.EnableEvents = False

Worksheets("SummaryClosingEntry").Range("C5").Valu e = _
Worksheets("ClosingEntry").Range("C5").Value +
.Value
Application.EnableEvents = True
End If
End If
End With

End Sub

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 Logic peyman Excel Discussion (Misc queries) 7 October 17th 07 11:13 PM
accumulator with other than one dan Excel Worksheet Functions 8 November 24th 06 06:29 PM
Two cell accumulator Bill Excel Worksheet Functions 1 January 3rd 05 03:15 PM
Please help me get this accumulator working Bill Craig[_3_] Excel Programming 1 May 19th 04 10:36 PM


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

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"