Hey Team,
I'm trying to transfer data between two tables on different sheets depending on the value of the Status Column.
Credit Snakehips for getting me this close.
I have 3 Codes. one for the module then one for each respective sheet I'm copying to.
This code works perfectly but I'm trying to tweak it to paste from one Table to another. Currently the data just gets pasted to the bottom row below the table and not actually inside of it.
Module Code
Sheet 1
Sheet 2
I'm trying to transfer data between two tables on different sheets depending on the value of the Status Column.
Credit Snakehips for getting me this close.
I have 3 Codes. one for the module then one for each respective sheet I'm copying to.
This code works perfectly but I'm trying to tweak it to paste from one Table to another. Currently the data just gets pasted to the bottom row below the table and not actually inside of it.
Module Code
VBA Code:
Sub MoveBasedOnValue(YsNo As String)
'Common Sub for a Code Module
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim ToSheet As Worksheet
Dim FroSheet As Worksheet
Select Case YsNo
Case "yes"
Set ToSheet = Sheets("Returned")
Set FroSheet = Sheets("Out")
Case "no"
Set ToSheet = Sheets("Out")
Set FroSheet = Sheets("Returned")
End Select
A = FroSheet.UsedRange.Rows.Count
B = ToSheet.UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(ToSheet.UsedRange) = 0 Then B = 0
End If
Set xRg = FroSheet.Range("H1:H" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = YsNo Then
xRg(C).EntireRow.Copy Destination:=ToSheet.Range("A" & B + 1)
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) = YsNo Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Sheet 1
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Sub for Returned sheet
Dim ToSht As String
Dim FroSht As String
Dim YsNo As String
Dim Z As Long
Dim xVal As String
On Error Resume Next
If Intersect(Target, Range("H:H")) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Z = 1 To Target.Count
If Target(Z).Value > 0 Then
'********************************
YsNo = "no"
'**********************************
Call MoveBasedOnValue(YsNo)
End If
Next
Application.EnableEvents = True
End Sub
Sheet 2
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Sub for Returned sheet
Dim ToSht As String
Dim FroSht As String
Dim YsNo As String
Dim Z As Long
Dim xVal As String
On Error Resume Next
If Intersect(Target, Range("H:H")) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Z = 1 To Target.Count
If Target(Z).Value > 0 Then
'********************************
YsNo = "yes"
'**********************************
Call MoveBasedOnValue(YsNo)
End If
Next
Application.EnableEvents = True
End Sub