0

This is regarding the following VBA:

Public Sub NewSheet()

   ActiveSheet.Copy after:=Worksheets(Worksheets.Count)
   Worksheets(Worksheets.Count).Name = Format(Date, "m.d.yy")
   Worksheets(Worksheets.Count).Range("A1") = Date
   Worksheets(Worksheets.Count - 1).Visible = xlSheetHidden

End Sub

I have been using this VBA in excel to help duplicate sheets and hide sheets dynamically. But we have decided to use Google Sheets because it is more iOS friendly and it is easier to use across multiple users.

Now I am at a loss as to how to use (convert) this VBA code to Google Script. Any help would be appreciated.

_/ \ _

2

1 Answer 1

3

Probably it can be done about this way:

function myFunction() {
  var ss        = SpreadsheetApp.getActiveSpreadsheet(); // current spreadsheet
  var old_sheet = ss.getActiveSheet();                   // current (old) sheet
  var new_sheet = old_sheet.copyTo(ss);                  // make a copy

  new_sheet.setName(Utilities.formatDate(new Date(), 'GMT', 'MM.dd.yy')); // set the name
  new_sheet.getRange('A1').setValue(new Date());         // set the cell A1
  old_sheet.hideSheet();                                 // hide the old sheet
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.