• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Move selected cell value to another selected area in same sheet

HI,
I am using MS Excel 2013 and I required a macro
1. Which move selected names from Table-1 to Table-2 (and sort on filled cells first) , when click on "ADD" button.
2. If I click on "Remove" button the selected names from Table-2 move to Table-1 and sort on filled cells.

I required as same as Excel Option >> More Commands works

Sample sheet attached for your reference.
 

Attachments

  • Sample_Sheet.xlsm
    27 KB · Views: 6
Try this Macro form tab1 to tab 2
you can write a similar nacro from tab 2 to tab1
Code:
Option Explicit
Sub insert_TO_2()
If Selection.Column = 4 And Selection.Row > 12 _
    And Selection.Columns.Count = 1 Then
    Dim lrH%, lrD%
    Dim my_cel As Range
        lrH = Cells(Rows.Count, "H").End(3).Row
     If lrH < 12 Then lrH = 12
     lrD = Cells(Rows.Count, "D").End(3).Row
            If lrD < 12 Then lrD = 12
         For Each my_cel In Selection
           If my_cel <> vbNullString Then
            my_cel.Cut Range("H" & lrH + 1)
            lrH = lrH + 1
           End If
         Next
  End If
  Range("h12:H" & lrH).SortSpecial
  Range("D12:D" & lrD).SortSpecial
 Application.CutCopyMode = False
End Sub
 
HI Salim,
Thanks for your reply, I have tried the code in both "ADD" and "Remove" buttons but it gives error when there are single row value left. Can you please help me to resolve the issue.

Thanks
Nitesh




Try this Macro form tab1 to tab 2
you can write a similar nacro from tab 2 to tab1
Code:
Option Explicit
Sub insert_TO_2()
If Selection.Column = 4 And Selection.Row > 12 _
    And Selection.Columns.Count = 1 Then
    Dim lrH%, lrD%
    Dim my_cel As Range
        lrH = Cells(Rows.Count, "H").End(3).Row
     If lrH < 12 Then lrH = 12
     lrD = Cells(Rows.Count, "D").End(3).Row
            If lrD < 12 Then lrD = 12
         For Each my_cel In Selection
           If my_cel <> vbNullString Then
            my_cel.Cut Range("H" & lrH + 1)
            lrH = lrH + 1
           End If
         Next
  End If
  Range("h12:H" & lrH).SortSpecial
  Range("D12:D" & lrD).SortSpecial
Application.CutCopyMode = False
End Sub
 
Back
Top