Hi there,
See if the attached workbook does what you need - it uses the following code:
ThisWorkbook VBA CodeModule:
Option Explicit
'=========================================================================================
'=========================================================================================
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Call MoveAlbum(rSource:=Target)
End Sub
Standard VBA CodeModule:
Option Private Module
Option Explicit
'=========================================================================================
'=========================================================================================
Public Sub MoveAlbum(rSource As Range)
Dim vaDataValues As Variant
Dim sTargetSheet As String
Dim iLastRowNo As Integer
Dim wksSource As Worksheet
Dim wksTarget As Worksheet
' Proceed only if the value of a single cell in the Status column has changed
If mbSelectionIsValid(rSource:=rSource) Then
' Locate the worksheet from which the record is being removed
Set wksSource = rSource.Parent
' Determine the name of the worksheet to which the record is being transferred
sTargetSheet = rSource.Value
' Proceed only if the name of the target worksheet has been determined
If sTargetSheet <> vbNullString Then
' Locate the worksheet to which the record is being transferred
Set wksTarget = ThisWorkbook.Worksheets(sTargetSheet)
' Locate the entire row in which the source record is located
With rSource.EntireRow
' Locate the first three cells in the above (source) row
With Range(.Cells(1, 1), .Cells(1, 3))
' Store the values of the above cells in an array variable
vaDataValues = .Value
' Clear the values from the three cells
.ClearContents
' Sort the records in the source worksheet to "remove" the empty row
With .EntireColumn
.Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Header:=xlYes
End With
End With
End With
' Move to the target worksheet
With wksTarget
' Determine the row number of the first empty row in the worksheet
iLastRowNo = .UsedRange.Rows(.UsedRange.Rows.Count).Row
iLastRowNo = iLastRowNo + 1
' Assign the values stored in the array variable to the first three cells
' in the first empty row in the target worksheet
With .Rows(iLastRowNo)
Range(.Cells(1, 1), .Cells(1, 3)).Value = vaDataValues
End With
' Sort the records in the target worksheet
.Cells.Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Header:=xlYes
End With
End If
End If
End Sub
'=========================================================================================
'=========================================================================================
Private Function mbSelectionIsValid(rSource As Range) As Boolean
Const sSTATUS_COLUMN As String = "C"
Dim iNoOfCells As Integer
Dim wksSource As Worksheet
Set wksSource = rSource.Parent
If Not Intersect(rSource, wksSource.Columns(sSTATUS_COLUMN)) Is Nothing Then
On Error Resume Next
iNoOfCells = 0
iNoOfCells = rSource.Cells.Count
On Error GoTo 0
If iNoOfCells = 1 Then
mbSelectionIsValid = True
Else: mbSelectionIsValid = False
End If
Else: mbSelectionIsValid = False
End If
End Function
I've modified things a little in that the dropdown list in each worksheet shows only the names of the two other worksheets - i.e. you don't have the option of transferring a data record from one worksheet to the same worksheet.
Also, the data records in the source and target worksheets are sorted by Album Name after each transfer operation.
Hope this helps - please let me know how you get on.
Regards,
Greg M
Bookmarks