ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ADDING/DELETING SHEETS WITHOUT LOSING FOCUS. (https://www.excelbanter.com/excel-programming/431716-adding-deleting-sheets-without-losing-focus.html)

Faraz A. Qureshi

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
I have a few sheets selected. How to have a new sheet be inserted at the
beginning, or deleting the first sheet, with the currently selected sheets
remaining to be selected.

A proper code for the same shall be obliged.

Thanx in advance.
--
Best Regards,

Faraz

Bob Phillips[_3_]

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
Dim sh As Worksheet

Set sh = ActiveSheet
Worksheets.Add befo=Worksheets(1)
sh.Activate


--
__________________________________
HTH

Bob

"Faraz A. Qureshi" wrote in
message ...
I have a few sheets selected. How to have a new sheet be inserted at the
beginning, or deleting the first sheet, with the currently selected sheets
remaining to be selected.

A proper code for the same shall be obliged.

Thanx in advance.
--
Best Regards,

Faraz




Faraz A. Qureshi

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
Thanx Bob!

However, this code I believe shall work only with a single sheet selected.
But what I have is a question pertaining to multiple sheets selected?

--
Best Regards,

Faraz


"Bob Phillips" wrote:

Dim sh As Worksheet

Set sh = ActiveSheet
Worksheets.Add befo=Worksheets(1)
sh.Activate


--
__________________________________
HTH

Bob

"Faraz A. Qureshi" wrote in
message ...
I have a few sheets selected. How to have a new sheet be inserted at the
beginning, or deleting the first sheet, with the currently selected sheets
remaining to be selected.

A proper code for the same shall be obliged.

Thanx in advance.
--
Best Regards,

Faraz





michdenis

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
Hi,
Try this :
'------------------------------
Sub test()
Dim Sh As Object, X As String
With Workbooks(ThisWorkbook.Name)
.Activate
Set Sh = ActiveWindow.SelectedSheets
X = .ActiveSheet.Name
.Worksheets.Add befo=Sheets(1)
Sh.Select
.Sheets(X).Activate
End With
End Sub
'------------------------------

"Faraz A. Qureshi" a écrit dans le message de
groupe de discussion : ...
I have a few sheets selected. How to have a new sheet be inserted at the
beginning, or deleting the first sheet, with the currently selected sheets
remaining to be selected.

A proper code for the same shall be obliged.

Thanx in advance.
--
Best Regards,

Faraz


Faraz A. Qureshi

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
Run-time Error '91':
Object variable or With block variable not set
The following line being highlighted:

X = .ActiveSheet.Name

--
Best Regards,

Faraz


"MichDenis" wrote:

Hi,
Try this :
'------------------------------
Sub test()
Dim Sh As Object, X As String
With Workbooks(ThisWorkbook.Name)
.Activate
Set Sh = ActiveWindow.SelectedSheets
X = .ActiveSheet.Name
.Worksheets.Add befo=Sheets(1)
Sh.Select
.Sheets(X).Activate
End With
End Sub
'------------------------------

"Faraz A. Qureshi" a écrit dans le message de
groupe de discussion : ...
I have a few sheets selected. How to have a new sheet be inserted at the
beginning, or deleting the first sheet, with the currently selected sheets
remaining to be selected.

A proper code for the same shall be obliged.

Thanx in advance.
--
Best Regards,

Faraz



michdenis

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
X = ActiveSheet.Name



"Faraz A. Qureshi" a écrit dans le message de
groupe de discussion : ...
Run-time Error '91':
Object variable or With block variable not set
The following line being highlighted:

X = .ActiveSheet.Name

--
Best Regards,

Faraz


"MichDenis" wrote:

Hi,
Try this :
'------------------------------
Sub test()
Dim Sh As Object, X As String
With Workbooks(ThisWorkbook.Name)
.Activate
Set Sh = ActiveWindow.SelectedSheets
X = .ActiveSheet.Name
.Worksheets.Add befo=Sheets(1)
Sh.Select
.Sheets(X).Activate
End With
End Sub
'------------------------------

"Faraz A. Qureshi" a écrit dans le message de
groupe de discussion :
...
I have a few sheets selected. How to have a new sheet be inserted at the
beginning, or deleting the first sheet, with the currently selected sheets
remaining to be selected.

A proper code for the same shall be obliged.

Thanx in advance.
--
Best Regards,

Faraz



Norie

ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.
 
Here's my go.


All times are GMT +1. The time now is 04:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com