Moving rows to different sheets based on drop down.

purevega

New Member
Joined
May 14, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello! Thank you in advance for visiting my post. I understand there have been a couple posts here already that ask for help regarding VBA code and moving data from one sheet to another based on a drop-down value, I appreciate your help nonetheless.

----------

We are approaching territory changes for our sales team, and the current process takes 4-5 months to complete which we are looking to cut down significantly. I believe we can achieve a more efficient process by introducing VBA code into our excel sheets and moving rows of data from one sheet to another (or from account manager to account manager). I've watch a beginner's tutorial on VBA code (and macros) which has been helpful but I believe what I'm trying to achieve is more advanced than my current knowledge and I'm willing to learn.

Below is a screenshot of an example sheet that includes the basic information we use for territory changes (although missing rollup totals of their entire portfolio), where we would move the respective rows to the individual selected in the drop down menu in column "E" to the end of the data of the respective person receiving the new account (see highlighted row in the second screenshot). Each sheet titled "Person X" has the same layout you see below as well.

Screenshot 1
Excel Code Help.png


Screenshot 2
Excel Code Help 2.png



I'm looking for help creating VBA code that would CUT/PASTE a row of data from one sheet to another that would eventually contribute to a roll-up total of column C somewhere on the sheet (could be the top or bottom, doesn't matter). Although I provided the basic information we use for territory changes, there may be some additional rows to be included to help with decision making - so a helpful note in the code where I can extend the selection of rows being cut/paste would be nice.


I'm extremely thankful for any help regarding this, and I'm looking forward to learning how VBA code works further and adding it to my arsenal of skills :)
 
Here is what we used last year and will use this year, column B will be used as the drop down containing sales team initials.

Apologies, I can't use the xl2bb due to work computer restrictions. Let me know how else I can help.
 

Attachments

  • Screenshot 2024-06-04 080401.png
    Screenshot 2024-06-04 080401.png
    148.3 KB · Views: 10
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim selectedName As String
    Dim currentRow As Long
    Dim lastCell As Range
 
    If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
        If Target.Cells.Count = 1 Then
            selectedName = Target.Value
         
            On Error Resume Next
            Set ws = ThisWorkbook.Sheets(selectedName)
            On Error GoTo 0
         
            If Not ws Is Nothing Then
                Application.EnableEvents = False
             
                currentRow = Target.Row
                Set lastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, _
                                            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
                If Not lastCell Is Nothing Then
                    lastRow = lastCell.Row + 1
                Else
                    lastRow = 1
                End If
             
                ws.Range("A" & lastRow) = Me.Range("A" & currentRow & ":J" & currentRow)
                Me.Rows(currentRow).Delete
                Application.EnableEvents = True
            Else
                MsgBox "Sheet named '" & selectedName & "' does not exist.", vbExclamation
            End If
        End If
    End If
End Sub
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim selectedName As String
    Dim currentRow As Long
    Dim lastCell As Range
 
    If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
        If Target.Cells.Count = 1 Then
            selectedName = Target.Value
        
            On Error Resume Next
            Set ws = ThisWorkbook.Sheets(selectedName)
            On Error GoTo 0
        
            If Not ws Is Nothing Then
                Application.EnableEvents = False
            
                currentRow = Target.Row
                Set lastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, _
                                            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
                If Not lastCell Is Nothing Then
                    lastRow = lastCell.Row + 1
                Else
                    lastRow = 1
                End If
            
                ws.Range("A" & lastRow) = Me.Range("A" & currentRow & ":J" & currentRow)
                Me.Rows(currentRow).Delete
                Application.EnableEvents = True
            Else
                MsgBox "Sheet named '" & selectedName & "' does not exist.", vbExclamation
            End If
        End If
    End If
End Sub
Thanks Cubist, I'll give it a try tomorrow.
 
Upvote 0

Forum statistics

Threads
1,223,934
Messages
6,175,487
Members
452,647
Latest member
MatthewBiersay

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