Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default circular reference

I have one cell for total time and another cell for total downtime. When a
user enters a number into either total time or into downtime i need to
automatically subtract the total downtime from the total time. The problem
is circular reference as the user has to enter the value into total time
before the calculation is made.

Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default circular reference

Hi, Enyaw,

Try pasting this code into the codesheet for the worksheet containing your
cells.
You may want to change the worksheet name and change the range names to cell
references, but it's easier if you apply the names "Total" and "DownTime" to
the two cells in question, then you don't need to change the code!

Pete

Private Sub Worksheet_Change(ByVal Target As Range)

Dim Total As Range
Set Total = Sheets("Sheet1").Range("Total")
Dim TotalIntersection As Range
Set TotalIntersection = Intersect(Target, Total)

Dim DownTime As Range
Set DownTime = Sheets("Sheet1").Range("DownTime")
Dim DownTimeIntersection As Range
Set DownTimeIntersection = Intersect(Target, DownTime)

On Error GoTo ErrorExit

Application.EnableEvents = True

If Not TotalIntersection Is Nothing Then 'If you change the Total value
Application.EnableEvents = False
Total.Value = Total.Value - DownTime.Value
Application.EnableEvents = True
End If

If Not DownTimeIntersection Is Nothing Then 'If you change the DownTime
value
Application.EnableEvents = False
Total.Value = Total.Value - DownTime.Value
Application.EnableEvents = True
End If

ErrorExit:
Exit Sub

End Sub




"enyaw" wrote:

I have one cell for total time and another cell for total downtime. When a
user enters a number into either total time or into downtime i need to
automatically subtract the total downtime from the total time. The problem
is circular reference as the user has to enter the value into total time
before the calculation is made.

Any help would be appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default circular reference

Actually, this is a little neater:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim Total As Range
Dim TotalIntersection As Range
Set Total = Sheets("Sheet1").Range("Total")
Set TotalIntersection = Intersect(Target, Total)

Dim DownTime As Range
Dim DownTimeIntersection As Range
Set DownTime = Sheets("Sheet1").Range("DownTime")
Set DownTimeIntersection = Intersect(Target, DownTime)

On Error GoTo ErrorExit

If Not TotalIntersection Is Nothing Or Not DownTimeIntersection Is
Nothing Then
Application.EnableEvents = False
Total.Value = Total.Value - DownTime.Value
Application.EnableEvents = True
End If

ErrorExit:
Exit Sub

End Sub


"enyaw" wrote:

I have one cell for total time and another cell for total downtime. When a
user enters a number into either total time or into downtime i need to
automatically subtract the total downtime from the total time. The problem
is circular reference as the user has to enter the value into total time
before the calculation is made.

Any help would be appreciated.

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
Circular Reference [email protected] Excel Worksheet Functions 4 September 13th 09 04:59 PM
circular reference Sasa Stankovic Excel Worksheet Functions 3 August 18th 08 03:58 PM
Help on Circular Reference, MIVELD Excel Discussion (Misc queries) 1 July 28th 06 10:23 AM
Circular reference Adella[_2_] Excel Programming 2 July 19th 05 01:58 AM
how to: circular reference Tim Excel Worksheet Functions 0 March 11th 05 12:37 AM


All times are GMT +1. The time now is 06:05 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"