ADDING/DELETING SHEETS WITHOUT LOSING FOCUS.

F

Faraz A. Qureshi

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.
 
B

Bob Phillips

Dim sh As Worksheet

Set sh = ActiveSheet
Worksheets.Add before:=Worksheets(1)
sh.Activate
 
F

Faraz A. Qureshi

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 said:
Dim sh As Worksheet

Set sh = ActiveSheet
Worksheets.Add before:=Worksheets(1)
sh.Activate
 
M

MichDenis

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 before:=Sheets(1)
Sh.Select
.Sheets(X).Activate
End With
End Sub
'------------------------------

"Faraz A. Qureshi" <[email protected]> a écrit dans le message de
groupe de discussion : (e-mail address removed)...
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.
 
F

Faraz A. Qureshi

Run-time Error '91':
Object variable or With block variable not set
The following line being highlighted:

X = .ActiveSheet.Name
 
M

MichDenis

X = ActiveSheet.Name



"Faraz A. Qureshi" <[email protected]> a écrit dans le message de
groupe de discussion : (e-mail address removed)...
Run-time Error '91':
Object variable or With block variable not set
The following line being highlighted:

X = .ActiveSheet.Name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top