View Full Version : [SOLVED:] Solved: Selectively copy ActiveCell onChange
simora
09-24-2009, 05:13 AM
How can you selectively copy the active cell.value to another worksheet
("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1)
only if it was BLANK before you changed its value.
In other words, if the cell had a value in it before you changed it, I dont want to copy it.
Thanks
mdmackillop
09-24-2009, 05:29 AM
Option Explicit
Dim OldVal
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
OldVal = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If OldVal = "" Then Target.Copy Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1)
End Sub
Bob Phillips
09-24-2009, 05:50 AM
Option Explicit
Private mPrev As Variant
Const WS_RANGE As String = "H1" '<== change to suit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If mPrev = "" Then
Target.Copy Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1)
End If
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
mPrev = Target.Value
End If
End Sub
This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.
simora
09-25-2009, 03:19 PM
Thanks all.
I got xld ' s code to work perfectly.
Wasn't quite able to follow all the logic of mdmackillop's code as the range area wasn't quite clear.
Thanks again
divakarganta
10-18-2012, 02:54 AM
Hi,
Worksheet_Change can apply on the respective sheet tab to fire this event. But I want this event to fire for all sheets to effect because I am using .xlam file for this task.
Pls give the solution
Thanks,
Divakar.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.