Simple macro to shift updates to an archived cell

phogon

New Member
Joined
Aug 22, 2018
Messages
7
I have a worksheet with 2 columns.

Column 1 is Latest update.
Column 2 is Archive update.

I want to write a macro that would detect the cell I've selected, copy its contents, and paste it into the top of the archived update cell.

BEFORE:

CELL A1 CELL B1
Update 5 Update 4
Update 3
Update 2
Update 1

After I select cell A1 and run the Macro

AFTER:

CELL A1 CELL B1
Update 5
Update 4
Update 3
Update 2
Update 1

I'm imagining a macro tht copy cells, offset (0,1), then paste content but I'm havin trouble retining existing data in the Column B cells
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
sorry for formatting,

basically before would be:
Column A = Update 5
Columm B = Update 4-1

After macro:
Column A = blank
Column B = Update 5-1
 
Upvote 0
Do you plan to select more then one update at a time?
And are you saying the updates have to stay in order in column A
So the script has to look at the last character which in this case is 4 and insert it between 5 and 3
Or can the latest update go to the top of the list in column A
 
Upvote 0
This here means the entire column A is empty is that true

You said

After macro:
Column A = blank
Column B = Update 5-1

Column A is blank not A1 is blank
 
Upvote 0
Try putting this in the SHEET code module (right-click sheet tab \ view code \ paste code in window on right)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim t
    If Target.Address(0, 0) = "A1" Then
        Application.EnableEvents = False
        t = Target.Value
        Application.Undo
        Range("A2").Insert Shift:=xlDown
        Range("A2") = Range("B1")
        Range("B1") = Range("A1")
        Range("A1") = t
        Application.EnableEvents = True
    End If

End Sub

It is triggered whenever value in A1 changes
 
Last edited:
Upvote 0
This here means the entire column A is empty is that true

You said

After macro:
Column A = blank
Column B = Update 5-1

Column A is blank not A1 is blank

Sorry. Just 1 cell at a time will change.
When I Say column A, I Mean A1 (orA2, or A3) depending on where my cursor is.
 
Upvote 0
Try putting this in the SHEET code module (right-click sheet tab \ view code \ paste code in window on right)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim t
    If Target.Address(0, 0) = "A1" Then
        Application.EnableEvents = False
        t = Target.Value
        Application.Undo
        Range("A2").Insert Shift:=xlDown
        Range("A2") = Range("B1")
        Range("B1") = Range("A1")
        Range("A1") = t
        Application.EnableEvents = True
    End If

End Sub

It is triggered whenever value in A1 changes

Can it be one where it only triggrs when Ipress a button. Basically I want to be able to select cell A15, click the button, thn the contents get moved to the top of cell B15.
 
Upvote 0
I think you need to show a before and after results:

Your original post had that but then you said that was incorrect and in your second example it was more confusing to me. And did not show a before and after.

And you never answered this question which I earlier asked:

And are you saying the updates have to stay in order in column A
So the script has to look at the last character which in this case is 4 and insert it between 5 and 3
Or can the latest update go to the top of the list in column A
 
Upvote 0
And you said if you select a cell in column A that cells data should be copied to column B

So just selecting the cell activates the script.
No change is required. Just selecting the cell any cell in column A send the data to next empty cell in column B

Is that what you want? You said select not change
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top