User selects row, then move data in certain cells from selected row to certain cells in the row above

Don4000

Board Regular
Joined
Jan 28, 2005
Messages
93
Hello Everyone

I wonder if someone could help with a problem I have been presented with

Could someone design a macro, that for the row that has been selected by the user, cuts data in certain cells of that row, and pastes the data into specific cells in the row above, as per the schedule below

Selected row Row above selected row

V T

W S

X Q

Y R



Eg

V22 is cut and pasted into T21

W22 is cut and pasted into S21

Etc


Once this has been completed, the selected row is deleted

I would be very grateful, for anyone’s help



Thank you

Don4000
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
If I select Y column, how do I know that I need to move data into R row? Is this logic hard-coded? Or there's some structure of the sheet that implies it?
 
Upvote 0
Let's start with this:

VBA Code:
Sub CopyDataDeleteRow()

    Dim ws As Worksheet
    Dim currRow As Long
    
    Set ws = ActiveSheet                    ' <--- Idealy change to named sheet using Worksheets("NameOfSheet")
    
    If Selection.Rows.Count > 1 Then
        MsgBox "Multiple rows selected exiting procedure"
        Exit Sub
    End If
    
    currRow = Selection.Row
    
    With ws
        .Range("T" & currRow - 1).Value = .Range("V" & currRow).Value
        .Range("S" & currRow - 1).Value = .Range("W" & currRow).Value
        .Range("Q" & currRow - 1).Value = .Range("X" & currRow).Value
        .Range("R" & currRow - 1).Value = .Range("Y" & currRow).Value
        
        .Rows(currRow).Delete
    End With
End Sub
 
Upvote 0
Solution
Alex, this works beautifully, and will help enormously
Thank you very much for helping
The skill and expertise here is just wonderful
Also a thank you to everyone who viewed the post
Happy New Year everyone

Don
 
Upvote 0
Another possibility without taking anything away from Alex's suggestion.
For multirow selection error you can copy Alex's error check.
Code:
Sub With_Array()
Dim ocArr, ncArr, nr As Long, i As Long
ocArr = Array(22, 23, 24, 25)
ncArr = Array(20, 19, 17, 18)
nr = Selection.Row - 1
    For i = LBound(ncArr) To UBound(ncArr)
        Cells(nr, ncArr(i)).Value = Cells(nr + 1, ocArr(i)).Value
    Next i
Rows(nr + 1).Delete
End Sub

Happy, Healthy and Prosperous New Year to all of you and yours.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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