Hello, Please I need your assistance with trying to copy active row to another worksheet based on drop-down. I have two worksheets: Requisition & Expenditure list respectively. I want a situation where when I click the drop-down list on Column H in Sheet 'Requisition' and select the option 'Fulfilled' , that particular row from 'B:G' will copy and paste on a new row in the 'Expenditure list' sheet.
I am currently using tables on both sheets and will like to keep it as such. I have tried the code below but it doesn't work
Sub Reqfulfilled()
Dim wsh As Worksheet, wsh2
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim tbl As ListObject, tbl2
Set wsh = Worksheets("REQUISITION")
Set wsh2 = Worksheets("EXPENDITURE LIST")
Set tbl = wsh2.ListObjects("expendituretbl")
Set tbl2 = wsh.ListObjects("requisitiontbl")
A = tbl.Rows.Count
B = tbl2.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("EXPENDITURE LIST").UsedRange) = 0 Then B = 0
End If
Set xRg = wsh.Range("H1:H" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Fulfilled" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("EXPENDITURE LIST").Range("A" & B + 1)
B = B + 1
End If
Worksheets("EXPENDITURE LIST").UsedRange.RemoveDuplicates Columns:=1, Header:=xlYes
Worksheets("EXPENDITURE LIST").UsedRange.SpecialCells(xlCellTypeBlanks).Delete xlShiftUp
Next
MsgBox ("Data has been entered")
Application.ScreenUpdating = True
End Sub
Any ideas?
I am currently using tables on both sheets and will like to keep it as such. I have tried the code below but it doesn't work
Sub Reqfulfilled()
Dim wsh As Worksheet, wsh2
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim tbl As ListObject, tbl2
Set wsh = Worksheets("REQUISITION")
Set wsh2 = Worksheets("EXPENDITURE LIST")
Set tbl = wsh2.ListObjects("expendituretbl")
Set tbl2 = wsh.ListObjects("requisitiontbl")
A = tbl.Rows.Count
B = tbl2.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("EXPENDITURE LIST").UsedRange) = 0 Then B = 0
End If
Set xRg = wsh.Range("H1:H" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Fulfilled" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("EXPENDITURE LIST").Range("A" & B + 1)
B = B + 1
End If
Worksheets("EXPENDITURE LIST").UsedRange.RemoveDuplicates Columns:=1, Header:=xlYes
Worksheets("EXPENDITURE LIST").UsedRange.SpecialCells(xlCellTypeBlanks).Delete xlShiftUp
Next
MsgBox ("Data has been entered")
Application.ScreenUpdating = True
End Sub
Any ideas?