If cell changed, move old value to side

Asked

Viewed 20 times

-1

I’m starting to use VBA with the office package, as I still know little I’m having difficulties to get this functionality.

I was trying to do something simple and I needed help to understand how it works:

I need that if a cell in column I is changed, its old contents be copied to another immediately column H, without having to click any button, eg:

I have the following situation:

H13: Text 01

I13: Text 02

After inserting the value - Text 03 - in I13, We would have as result

H13: Text 02

I13: Text 03

I know I can do this with VBA, but I need the VBA syntax to start doing something more advanced.

2 answers

0

I was using the following code.. but he was copying the current value, wanted it to copy the last existing value... and wanted it to work only if the H column is not empty...

0

Option Explicit

Private Const H As Long = 8

Private Sub Worksheet_change(Byval Target As Range)

On Error GoTo CleanExit

Application.EnableEvents = False

Dim Coluna As Long

Dim linha As Long

Coluna = Target.Column

If Coluna = 9 Then

    linha = Target.Row

    Cells(linha, 8) = Cells(linha, Coluna)

End If

Cleanexit:

Application.EnableEvents = True

On Error GoTo 0

End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.