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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,517
Messages
5,832,223
Members
430,116
Latest member
d1pakjha

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