LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default How can I leave the contents of a cell alone in an IF statemen

Hi Ken,

If my interpretation of your question is correct I would like to add
that it is not a very good way to handle your data.
Say you wish to correct a column B value after the column C value had
already been added and therefore converted to the sum of the B and C
values. Excel can't then revise the new column C value because there is
no record of the original value typed in by the user. If the user
neglects to reenter the original column C value (I assume stored on
Paper or some other medium external to Excel) after revising a column B
value the worksheet will contain an error. The only solution to that
would be to prompt the user to reenter the original column C value if
the corresponding B cell was changed while the C cell is not blank.
All too complicated.

The following code changes incorrect C values to "Re-Enter" and a
MsgBox prompts the user to re-enter those C values that would be
incorrect because of a review of the B value...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, _
Range("C2:C" & Rows.Count)) Is Nothing Then
With Application
..EnableEvents = False
..ScreenUpdating = False
End With
Dim rngCell As Range
For Each rngCell In Intersect(Target, _
Range("C2:C" & Rows.Count))
On Error Resume Next
rngCell.Value = rngCell.Value + _
rngCell.Offset(0, -1).Value
Next rngCell
End If
If Not Intersect(Target, _
Range("B2:B" & Rows.Count)) Is Nothing Then
Dim blnReEnter As Boolean
For Each rngCell In Intersect(Target, _
Range("B2:B" & Rows.Count)).Offset(0, 1)
If rngCell.Value < "" Then
rngCell.Value = "Re-Enter"
blnReEnter = True
End If
Next rngCell
End If
If blnReEnter Then MsgBox _
"One or more Column C values need to be re-entered"
blnReEnter = False
Application.EnableEvents = True
End Sub

However, you should instead have separate columns for the original C
values and the sum of B and C values, removing the need for any code.

Ken Johnson

 
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
Formulas to copy contents of one cell in a worksheet to another ce Coachy Excel Discussion (Misc queries) 1 November 11th 06 02:13 AM
Selectively Clearing cell contents jdd Excel Worksheet Functions 2 April 22nd 06 04:06 AM
Returning Cell Value if someone deletes the contents of a cell mmc308 Excel Worksheet Functions 4 March 31st 06 06:41 PM
How do I get a number or letter to represent cell contents? Formula help Excel Discussion (Misc queries) 2 February 25th 06 11:51 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM


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