PDA

View Full Version : Delete from one cell and place in another automatically



ctuna
02-28-2008, 03:23 PM
I have a cell I enter a number in for tracking purposes. What I am trying to do is place the number I delete in another cell automatically when I delete it.

EXample: L1 = 1274, when I click on the box and delete it, It would move. L7= 1274


Any suggestions?

tstav
02-28-2008, 04:56 PM
EXample: L1 = 1274, when I click on the box and delete it, It would move. L7= 1274


What box is that???

Bob Phillips
02-28-2008, 05:16 PM
Private prev As Variant

Const WS_RANGE As String = "L1" '<== 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 .Value = "" Then .Offset(6, 0).Value = prev
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
prev = 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.

ctuna
02-28-2008, 06:00 PM
Works Fine

As usual I didn't explain it right.:mkay

I have a column of cells D 4 - D 200, I put numbers in these cells to represent a job. When I delete the number I want it to show up in column H 4 - H 200

Ex: D 4 = 1567 when I select the number and delete it will show up in H 4 = 1567

D 5 = 1265 when I select the number and delete it will show up in H 5 = 1265

Bob Phillips
02-28-2008, 06:13 PM
Private prev As Variant

Const WS_RANGE As String = "D4:D200" '<== 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 .Value = "" Then .Offset(0,4).Value = prev
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
prev = Target.Value
End If
End Sub

ctuna
02-29-2008, 08:19 AM
Works perfect in a new workbook.

When I put it in the workbook I am using it shows:

Compile Error:
Ambiguous name detected: Worksheet_Change


Any Suggestions