Moving a Sheet From the First Position to the Last

Imaginativeone

New Member
Joined
Mar 6, 2008
Messages
9
All of this code works like a charm, except for the following:

iWorkbook.Sheets("testSheet").Move + " After:=" + iWorkbook.Sheets(2);

How do I code the Move function with JavaScript? I've tried fixing the spacing, the correct object appears to be in operation.

Many, many thanks for your help.

Code:
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// function serviceInitExcel($scope)                                     //
// Version:                                                              //
// Description: Initialize Excel Spreadsheet                             //
// Date:                                                                 //
// To Do:                                                                //
// Author:                                                               //
//                                                                       //
///////////////////////////////////////////////////////////////////////////
var serviceInitExcel = function() {
 var _SCFR;
 var _filename = "emptyServiceValue";
 var _serviceBrowser = "";
 var service = {};
 service.soundOff = function() {
 
  alert("Another generic method");
 
 }
 
 service.initExcel = function() {
  var _scfr = new ActiveXObject("Excel.Application");
   _scfr.Visible = true;
   _scfr.Workbooks.Add;
   
  // alert("Application Initialized: " + _scfr.Name);
  
  _SCFR = _scfr;
  
  return _SCFR;
 
 } // genericMethod
 service.createSheet = function(iWorkbook, sheetName) {
  var pblSheet = iWorkbook.Sheets("Payable");
   pblSheet.Range("A1").Value = "Payable Sheet";
   
   pblSheet.Select;
  
  var newSheet = iWorkbook.Worksheets.Add;
  
   newSheet.Name = sheetName;
   
   newSheet.Select
   
   newSheet.Range("A1").Value = "_SCFR.Name: "     + _SCFR.Name;
   newSheet.Range("A2").Value = "ActiveWorkbook: " + _SCFR.ActiveWorkbook.Name;
   newSheet.Range("A3").Value = "Sheet 1: " + _SCFR.ActiveWorkbook.Sheets(1).Name;
   newSheet.Range("A4").Value = "Sheet 2: " + _SCFR.ActiveWorkbook.Sheets(2).Name;
   newSheet.Range("A5").Value = "Sheet 3: " + _SCFR.ActiveWorkbook.Sheets(3).Name;
   
   newSheet.Range("A6").Value = "testSheet: " + iWorkbook.Sheets("testSheet").Name;
   newSheet.Range("A7").Value = "Payable: "   + iWorkbook.Sheets("Payable").Name;
   newSheet.Range("A8").Value = "Paid: "      + iWorkbook.Sheets("Paid").Name;
   /* for (var s=0; s < 10; s++) {
   
    newSheet.Range("A9").Value = s;
   
    newSheet.Select
    
    iWorkbook.Sheets("Payable").Select
   
   } */
   // for (var i=0; i < 4; i++) { a.Selection.Insert   + " Shift:=xlDown"; }
   iWorkbook.Sheets("testSheet").Move + " After:=" + iWorkbook.Sheets(2);
   
   // newSheet.Move + "After:=" + iWorkbook.Sheets(3);
      
      // Sheets("Payable").Select
      // Sheets.Add
      // Sheets("Sheet6").Select
      // Sheets("Sheet6").Move After:=Sheets(3)
   // _SCFR.Workbooks("Book1.xlsx").Sheets("testSheet").Move + "After:=" + _SCFR.Workbooks("Book1.xlsx").Sheets("Payable");
   
  return iWorkbook;
 
 } // genericMethod
 return service;
}
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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