dannyok90
Board Regular
- Joined
- Aug 30, 2016
- Messages
- 115
Hi all,
I have two sets of code (below) to move cells up and down using two little up and down buttons at the beginning of each row.
For context, the spreadsheet is for adding subtasks into a project plan, that may need to switch places in the progressive order hence the up and down arrow keys.
In the upper 4 cells there are titles and countas etc. that so would like the up arrow to not move a row above the 4th line if the button is accidentally clicked for example.
Again for the down arrow I would not like to not go past the bottom row because that goes into a different section of the plan, and its where new rows get inserted.
I imagine using a helper column or something but I'm not sure..
Any help?
Thanks,
Dan
I have two sets of code (below) to move cells up and down using two little up and down buttons at the beginning of each row.
For context, the spreadsheet is for adding subtasks into a project plan, that may need to switch places in the progressive order hence the up and down arrow keys.
In the upper 4 cells there are titles and countas etc. that so would like the up arrow to not move a row above the 4th line if the button is accidentally clicked for example.
Again for the down arrow I would not like to not go past the bottom row because that goes into a different section of the plan, and its where new rows get inserted.
I imagine using a helper column or something but I'm not sure..
Any help?
Thanks,
Dan
Code:
Sub RowsUp()
' Mainlineup Macro
Dim b As Object, cs As Integer
Set b = ActiveSheet.Buttons(Application.Caller)
With b.TopLeftCell
cs = .Row
Rows(cs).Select
Selection.Cut
Selection.Offset(.Rows.Count - 2).Insert
.Select
End With
End Sub
Code:
Sub RowsDown()
' Mainlineup Macro
Dim b As Object, cs As Integer
Set b = ActiveSheet.Buttons(Application.Caller)
With b.TopLeftCell
cs = .Row
Rows(cs).Select
Selection.Cut
Selection.Offset(.Rows.Count + 1).Insert
.Select
End With
End Sub