VBA code "delete row if false"

TigraRed

New Member
Joined
Mar 24, 2021
Messages
2
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
Hello, Need help with my VBA code.
I need to write a script for this kind of task:
1. If on main sheet tick box is true I need the row to be copied on Completed sheet. Here is that part of script:



VBA Code:
function onEdit(event) {
  // assumes source data in sheet named Main
  // target sheet of move to named Complited
  // getColumn with check-boxes is currently set to column 2 or B
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "Main" && r.getColumn() == 2 && r.getValue() == true) {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("Complited");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).copyTo(target);


2. If the tick box is unmarked (false) I need that row to be removed from the Complited sheet.
} else if(s.getName() == "Complited" && r.getColumn() == 2 && r.getValue() == false) {

what next?

3. is it possible to make synced tickboxes between two sheets? E.g. If I am removing the tick from the Complited sheet the row should be deleted from the complited, also the tick should be removed also from the Main sheet row?

p.s. pardon for my English((
 

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

Watch MrExcel Video

Forum statistics

Threads
1,130,176
Messages
5,640,611
Members
417,157
Latest member
nirmalp

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
Top