Excel VBA Referencing Col Number from Named Range

p9087

New Member
Joined
Jul 22, 2019
Messages
1
Hi, in the code below I am trying to reference the column number within setColumnFilterCriteria from the named range AttendeeStatus so that this piece works no matter where this column is. Any ideas on how to do so?

Code:
function FilterAttendees() {  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('AttendeeStatus').activate();
  spreadsheet.getRange('AttendeeStatus').createFilter();
  spreadsheet.getRange('AttendeeStatus').activate();
  var criteria = SpreadsheetApp.newFilterCriteria()
  .setHiddenValues(['', 'Attending'])
  .build();
 
  spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(, criteria);
  spreadsheet.getActiveSheet().setName('Registrants');


  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.insertSheet(1);
  spreadsheet.getCurrentCell().activate();
  spreadsheet.getActiveSheet().setName('Attendees');
  spreadsheet.getCurrentCell().activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Registrants'), true);
  var sheet = spreadsheet.getActiveSheet();
  sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Attendees'), true);
  spreadsheet.getRange('Registrants!A1:Z500').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('AttendeeStatus').activate();
  spreadsheet.getActiveSheet().getFilter().remove();
  
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('1:1').activate();
  spreadsheet.getActiveRangeList().setFontWeight('bold');
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Attendees'), true);
  spreadsheet.getRange('1:1').activate();
  spreadsheet.getActiveRangeList().setFontWeight('bold');
};
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hello P9807,

Welcome!

You do realize you posted Google Apps Script code in a VBA forum, yes?
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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