Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Paste Once No Format Change Help

Hello,

I'm currently using the following in a spreadsheet to flag data that is
changed in any cell.

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Cells.Font.ColorIndex = 3 'ColorIndex = 3 = Red
End Sub

I would like to change this to only become active if a cell already has data
in it, prior to editing. I assume this would require a VLOOKUP expression but
I cannot figure out how to write it. Any assistance would be appreciated.

Thank you.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Paste Once No Format Change Help

Worksheet change only runs after the data has been changed to you can't tell
if data was in the cell previously. You need another cells that contain s
the previous data. For example, if you change A1 check B1 to see if it is
empty. If B1 is empty copy the data from A1 to B1. Then use B1 in your
spreadsheet s the final value.

"CCorreia" wrote:

Hello,

I'm currently using the following in a spreadsheet to flag data that is
changed in any cell.

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Cells.Font.ColorIndex = 3 'ColorIndex = 3 = Red
End Sub

I would like to change this to only become active if a cell already has data
in it, prior to editing. I assume this would require a VLOOKUP expression but
I cannot figure out how to write it. Any assistance would be appreciated.

Thank you.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Paste Once No Format Change Help

Try the following code. Whenever you select a (single) cell, it stores the
value of that cell in a variable. The Worksheet_Change event then looks at
that variable to see if the cell was empty before it was changed. Seems to
work pretty well for individual cells but not for mutiple-cell ranges.

Dim PrevVal

Private Sub Worksheet_Change(ByVal Target As Range)
If Len(PrevVal) 0 Then
Target.Cells.Font.ColorIndex = 3 'ColorIndex 3 = Red
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
'Store the value of the currently selected cell.
PrevVal = Target.Value
'If Target is empty, rest its font color.
If Len(Target.Value) = 0 Then
Target.Cells.Font.ColorIndex = xlAutomatic
End If
End Sub

This code all goes in the code module for the worksheet where you want this
to work.

Hope this helps,

Hutch

"CCorreia" wrote:

Hello,

I'm currently using the following in a spreadsheet to flag data that is
changed in any cell.

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Cells.Font.ColorIndex = 3 'ColorIndex = 3 = Red
End Sub

I would like to change this to only become active if a cell already has data
in it, prior to editing. I assume this would require a VLOOKUP expression but
I cannot figure out how to write it. Any assistance would be appreciated.

Thank you.


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
Lock Cell Format - Allow copy and paste of data without format change Chris12InKC Excel Worksheet Functions 2 May 9th 23 07:42 PM
Sudden Change in Copy & Paste Format GPBurdell Excel Discussion (Misc queries) 2 August 18th 08 06:02 PM
change the default paste format in excel 2007 Derfel Excel Discussion (Misc queries) 1 April 3rd 08 06:58 PM
Can I fix a format so it doesn't change when I drag or copy/paste Blah-blah Excel Worksheet Functions 1 February 15th 07 06:17 PM
copy & paste and change format SLB Excel Worksheet Functions 2 August 9th 06 01:26 PM


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