Copy row after change to another sheet. VBA

Wasyl

New Member
Joined
Feb 15, 2018
Messages
4
Hello

I am new at the forum and also new to VBA. However I have quite ambitious exercise to do.
I have workbook with two sheets: Sheet1 and Sheet2. Sheet1 is defined as table (this is important).
I want to copy cell B, D and F of the last row in Sheet1 once the cell in column G is filled up with string "ok" to the first empty row of Sheet2.
I tried to modify VBA code found here:
https://www.mrexcel.com/forum/excel...eet-into-another-worksheet-same-workbook.html
but with no success as there is a table in Sheet1 which happened to be incompatible with Insert instruction. It works if I remove table.

I copied these few lines of code below for your convinience. This procedure moves entire row between two sheets.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDest As Range
Set rngDest = Sheet2.Range("rngDest")
' Limit the trap area to range of cells in which completed dates are entered as defined above
If Not Intersect(Target, Sheet1.Range("rngTrigger")) Is Nothing Then
' Only trigger if the value entred is OK
If UCase(Target) = "OK" Then
'Ensure subsequent deletion of 'moved' row does NOT cause the Change Event to run again and get itself in a loop!
Application.EnableEvents = False
Target.EntireRow.Select
Selection.Cut
rngDest.Insert Shift:=xlDown
Selection.Delete
' Reset EnableEvents
Application.EnableEvents = True
End If
Else
End If
End Sub

where rngTrigger is defined name in Sheet1 refering to column G:G and rngDest is defined name in Sheet2 refering to first empty row.
Can you help me please?
And sorry for my English :)

--
Piotr
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,948
Messages
6,175,573
Members
452,652
Latest member
eduedu

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