Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Macro that can switch between tabs

I wish to create a macro that basically creates a new tab and copies the
information from the old tab to the new tab.

The issue is that the tab names will vary between different users and the
number of tabs will increase regularly.

I have very limited experience with visual basic so every assistance would
be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Macro that can switch between tabs

Can be done. Where do you want the new sheets inserted? Before first sheet,
before or after the active sheet or at the end.

I assume that you want the user to be able to input a name for the sheet.
The system will be able to check if the name exists and if so, request
another name form the user.

Regards,

OssieMac

"JorgeG.ACT" wrote:

I wish to create a macro that basically creates a new tab and copies the
information from the old tab to the new tab.

The issue is that the tab names will vary between different users and the
number of tabs will increase regularly.

I have very limited experience with visual basic so every assistance would
be greatly appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Macro that can switch between tabs

I didnt wait for your answer to my question. However, see what this does for
you.
The following code adds a worksheet to an active workbook and copies the
active work sheet to the new work sheet.
Because you said that you have limited experience with Visual Basic, I will
step through what you need to do.
Ensure that you have a backup copy of your workbook in case the macro does
not do exactly what you want.
The macro is designed to be run from the active sheet in the workbook and
this is the one it copies to the new sheet.

Shift/F11 will open the VBA Editor.
Select the menu item Insert-Module.
Copy the code into the module.

A single quote is used to mark text as a remark and the text should be
green. (This text is ignored by the program.)
If there are any lines in red then it is probably because the lines ended up
with a line feed between when I posted the code and you copied it into the
VBA editor. Use the delete key at the end of the first red line in the group
and bring the following red lines up into one line and when you move off the
line it should be black (with a bit of blue).

You will see some code with comments that gives you options on where you
want the new worksheet to be placed. As I have posted the code, the only
active one is the first one which places the worksheet before the first
existing worksheet. Only one of these lines is to be active but you can
change where you want the worksheet by placing a single quote in front of the
existing active one and remove the single quote from one of the others.

Close the VBA Editor and then save the workbook. If you are working in
xl2007 then save as a macro enabled workbook.

To run the macro select from the workbook menu items. If the macro does what
you want, then I will think about a toolbar button for you to run it but let
us get it doing what you want first.

All users will need to have options set to €˜macro enabled. Look up help on
this if you are unsure what to do here.

Sub Insert_New_Sheet()
Dim oldShtName As String
Dim newShtName As String
Dim wSht As Object
Dim wShtExists As Boolean
Dim inputPrompt As String

oldShtName = ActiveSheet.Name

inputPrompt = "Enter name for new sheet"

Do
wShtExists = False
Beep
newShtName = InputBox(prompt:=inputPrompt, _
Title:="New Sheet Name")
For Each wSht In Sheets
If LCase(wSht.Name) = LCase(newShtName) Then
wShtExists = True
inputPrompt = _
"Worksheet name already exists. Enter new name"
End If
Next wSht
Loop While wShtExists = True


'Following line adds sheet as first sheet
Sheets.Add Befo=Sheets(1)

'Following line adds sheet before active sheet
'Sheets.Add Befo=Sheets(oldShtName)

'Following line adds sheet after active sheet
'Sheets.Add After:=Sheets(oldShtName)

'Following line adds sheet after last sheet
'Sheets.Add After:=Sheets(Sheets.Count)

ActiveSheet.Name = newShtName
Sheets(oldShtName).Cells.Copy
Sheets(newShtName).Paste
Application.CutCopyMode = False
Range("A1").Select

End Sub

Regards,

OssieMac

"OssieMac" wrote:

Can be done. Where do you want the new sheets inserted? Before first sheet,
before or after the active sheet or at the end.

I assume that you want the user to be able to input a name for the sheet.
The system will be able to check if the name exists and if so, request
another name form the user.

Regards,

OssieMac

"JorgeG.ACT" wrote:

I wish to create a macro that basically creates a new tab and copies the
information from the old tab to the new tab.

The issue is that the tab names will vary between different users and the
number of tabs will increase regularly.

I have very limited experience with visual basic so every assistance would
be greatly appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Macro that can switch between tabs

Thanks OssieMac,

It worked brilliently, very impressive indeed.

One more thing though, one particular cell I would like to be paste linked.
Is that possible?


"OssieMac" wrote:

I didnt wait for your answer to my question. However, see what this does for
you.
The following code adds a worksheet to an active workbook and copies the
active work sheet to the new work sheet.
Because you said that you have limited experience with Visual Basic, I will
step through what you need to do.
Ensure that you have a backup copy of your workbook in case the macro does
not do exactly what you want.
The macro is designed to be run from the active sheet in the workbook and
this is the one it copies to the new sheet.

Shift/F11 will open the VBA Editor.
Select the menu item Insert-Module.
Copy the code into the module.

A single quote is used to mark text as a remark and the text should be
green. (This text is ignored by the program.)
If there are any lines in red then it is probably because the lines ended up
with a line feed between when I posted the code and you copied it into the
VBA editor. Use the delete key at the end of the first red line in the group
and bring the following red lines up into one line and when you move off the
line it should be black (with a bit of blue).

You will see some code with comments that gives you options on where you
want the new worksheet to be placed. As I have posted the code, the only
active one is the first one which places the worksheet before the first
existing worksheet. Only one of these lines is to be active but you can
change where you want the worksheet by placing a single quote in front of the
existing active one and remove the single quote from one of the others.

Close the VBA Editor and then save the workbook. If you are working in
xl2007 then save as a macro enabled workbook.

To run the macro select from the workbook menu items. If the macro does what
you want, then I will think about a toolbar button for you to run it but let
us get it doing what you want first.

All users will need to have options set to €˜macro enabled. Look up help on
this if you are unsure what to do here.

Sub Insert_New_Sheet()
Dim oldShtName As String
Dim newShtName As String
Dim wSht As Object
Dim wShtExists As Boolean
Dim inputPrompt As String

oldShtName = ActiveSheet.Name

inputPrompt = "Enter name for new sheet"

Do
wShtExists = False
Beep
newShtName = InputBox(prompt:=inputPrompt, _
Title:="New Sheet Name")
For Each wSht In Sheets
If LCase(wSht.Name) = LCase(newShtName) Then
wShtExists = True
inputPrompt = _
"Worksheet name already exists. Enter new name"
End If
Next wSht
Loop While wShtExists = True


'Following line adds sheet as first sheet
Sheets.Add Befo=Sheets(1)

'Following line adds sheet before active sheet
'Sheets.Add Befo=Sheets(oldShtName)

'Following line adds sheet after active sheet
'Sheets.Add After:=Sheets(oldShtName)

'Following line adds sheet after last sheet
'Sheets.Add After:=Sheets(Sheets.Count)

ActiveSheet.Name = newShtName
Sheets(oldShtName).Cells.Copy
Sheets(newShtName).Paste
Application.CutCopyMode = False
Range("A1").Select

End Sub

Regards,

OssieMac

"OssieMac" wrote:

Can be done. Where do you want the new sheets inserted? Before first sheet,
before or after the active sheet or at the end.

I assume that you want the user to be able to input a name for the sheet.
The system will be able to check if the name exists and if so, request
another name form the user.

Regards,

OssieMac

"JorgeG.ACT" wrote:

I wish to create a macro that basically creates a new tab and copies the
information from the old tab to the new tab.

The issue is that the tab names will vary between different users and the
number of tabs will increase regularly.

I have very limited experience with visual basic so every assistance would
be greatly appreciated.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Macro that can switch between tabs

Thanks for the kudos. Its nice to have a win sometimes so you have made my
day. Flattery gets you everywhere so if you can give me the following
details, I will attempt to do the link thing for you but it is dependent on
just what is needed so if you can provide the following info I will see what
I can do.
Does the link already exist on the old sheet and not copying properly?
Does it link back to the old sheet or to something else?
Which cell reference on the new sheet for the link?
What is sheet name and cell reference to which it is linked?
Can you create the link manually? If so, then create it and then select the
cell and then on the formula bar at the top, highlight the formula and then
copy it and then paste it into a posting here.

Regards,

OssieMac


"JorgeG.ACT" wrote:

Thanks OssieMac,

It worked brilliently, very impressive indeed.

One more thing though, one particular cell I would like to be paste linked.
Is that possible?


"OssieMac" wrote:

I didnt wait for your answer to my question. However, see what this does for
you.
The following code adds a worksheet to an active workbook and copies the
active work sheet to the new work sheet.
Because you said that you have limited experience with Visual Basic, I will
step through what you need to do.
Ensure that you have a backup copy of your workbook in case the macro does
not do exactly what you want.
The macro is designed to be run from the active sheet in the workbook and
this is the one it copies to the new sheet.

Shift/F11 will open the VBA Editor.
Select the menu item Insert-Module.
Copy the code into the module.

A single quote is used to mark text as a remark and the text should be
green. (This text is ignored by the program.)
If there are any lines in red then it is probably because the lines ended up
with a line feed between when I posted the code and you copied it into the
VBA editor. Use the delete key at the end of the first red line in the group
and bring the following red lines up into one line and when you move off the
line it should be black (with a bit of blue).

You will see some code with comments that gives you options on where you
want the new worksheet to be placed. As I have posted the code, the only
active one is the first one which places the worksheet before the first
existing worksheet. Only one of these lines is to be active but you can
change where you want the worksheet by placing a single quote in front of the
existing active one and remove the single quote from one of the others.

Close the VBA Editor and then save the workbook. If you are working in
xl2007 then save as a macro enabled workbook.

To run the macro select from the workbook menu items. If the macro does what
you want, then I will think about a toolbar button for you to run it but let
us get it doing what you want first.

All users will need to have options set to €˜macro enabled. Look up help on
this if you are unsure what to do here.

Sub Insert_New_Sheet()
Dim oldShtName As String
Dim newShtName As String
Dim wSht As Object
Dim wShtExists As Boolean
Dim inputPrompt As String

oldShtName = ActiveSheet.Name

inputPrompt = "Enter name for new sheet"

Do
wShtExists = False
Beep
newShtName = InputBox(prompt:=inputPrompt, _
Title:="New Sheet Name")
For Each wSht In Sheets
If LCase(wSht.Name) = LCase(newShtName) Then
wShtExists = True
inputPrompt = _
"Worksheet name already exists. Enter new name"
End If
Next wSht
Loop While wShtExists = True


'Following line adds sheet as first sheet
Sheets.Add Befo=Sheets(1)

'Following line adds sheet before active sheet
'Sheets.Add Befo=Sheets(oldShtName)

'Following line adds sheet after active sheet
'Sheets.Add After:=Sheets(oldShtName)

'Following line adds sheet after last sheet
'Sheets.Add After:=Sheets(Sheets.Count)

ActiveSheet.Name = newShtName
Sheets(oldShtName).Cells.Copy
Sheets(newShtName).Paste
Application.CutCopyMode = False
Range("A1").Select

End Sub

Regards,

OssieMac

"OssieMac" wrote:

Can be done. Where do you want the new sheets inserted? Before first sheet,
before or after the active sheet or at the end.

I assume that you want the user to be able to input a name for the sheet.
The system will be able to check if the name exists and if so, request
another name form the user.

Regards,

OssieMac

"JorgeG.ACT" wrote:

I wish to create a macro that basically creates a new tab and copies the
information from the old tab to the new tab.

The issue is that the tab names will vary between different users and the
number of tabs will increase regularly.

I have very limited experience with visual basic so every assistance would
be greatly appreciated.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Macro that can switch between tabs

Your Welcome OssieMac,
It's great to get someone who not only knows what they are doing but is
prepared to actually help.To fill you in a little. Firstly, the spreadheet is
used by many staff members, so its not simply my limitations I'm dealing
with here.

I had a macro which was "crudely" created using the Macro recording
facility. It cleared information from the new sheet which is manually copied;
clearly Macros created this way have limitations hence my request for
assistance as I'm trying to make this process as user friendly as possible.
Thats where your macro has made a real improvement.

Currently there are only references to other cells on the same sheet, but no
links between sheets. What I need is for cell B21 in the new sheet to link
back to field B34 in the old sheet. Currently the name of the sheet is a date
such as 30-5-07 hence the paste link formula being as follows:
='30-5-07'!$B$34.

By the way I have created tool bar buttons to run macros before, so that is
one less thing you will need to concentrate on.

Regards
Jorgeg.ACT

"OssieMac" wrote:

Thanks for the kudos. Its nice to have a win sometimes so you have made my
day. Flattery gets you everywhere so if you can give me the following
details, I will attempt to do the link thing for you but it is dependent on
just what is needed so if you can provide the following info I will see what
I can do.
Does the link already exist on the old sheet and not copying properly?
Does it link back to the old sheet or to something else?
Which cell reference on the new sheet for the link?
What is sheet name and cell reference to which it is linked?
Can you create the link manually? If so, then create it and then select the
cell and then on the formula bar at the top, highlight the formula and then
copy it and then paste it into a posting here.

Regards,

OssieMac


"JorgeG.ACT" wrote:

Thanks OssieMac,

It worked brilliently, very impressive indeed.

One more thing though, one particular cell I would like to be paste linked.
Is that possible?


"OssieMac" wrote:

I didnt wait for your answer to my question. However, see what this does for
you.
The following code adds a worksheet to an active workbook and copies the
active work sheet to the new work sheet.
Because you said that you have limited experience with Visual Basic, I will
step through what you need to do.
Ensure that you have a backup copy of your workbook in case the macro does
not do exactly what you want.
The macro is designed to be run from the active sheet in the workbook and
this is the one it copies to the new sheet.

Shift/F11 will open the VBA Editor.
Select the menu item Insert-Module.
Copy the code into the module.

A single quote is used to mark text as a remark and the text should be
green. (This text is ignored by the program.)
If there are any lines in red then it is probably because the lines ended up
with a line feed between when I posted the code and you copied it into the
VBA editor. Use the delete key at the end of the first red line in the group
and bring the following red lines up into one line and when you move off the
line it should be black (with a bit of blue).

You will see some code with comments that gives you options on where you
want the new worksheet to be placed. As I have posted the code, the only
active one is the first one which places the worksheet before the first
existing worksheet. Only one of these lines is to be active but you can
change where you want the worksheet by placing a single quote in front of the
existing active one and remove the single quote from one of the others.

Close the VBA Editor and then save the workbook. If you are working in
xl2007 then save as a macro enabled workbook.

To run the macro select from the workbook menu items. If the macro does what
you want, then I will think about a toolbar button for you to run it but let
us get it doing what you want first.

All users will need to have options set to €˜macro enabled. Look up help on
this if you are unsure what to do here.

Sub Insert_New_Sheet()
Dim oldShtName As String
Dim newShtName As String
Dim wSht As Object
Dim wShtExists As Boolean
Dim inputPrompt As String

oldShtName = ActiveSheet.Name

inputPrompt = "Enter name for new sheet"

Do
wShtExists = False
Beep
newShtName = InputBox(prompt:=inputPrompt, _
Title:="New Sheet Name")
For Each wSht In Sheets
If LCase(wSht.Name) = LCase(newShtName) Then
wShtExists = True
inputPrompt = _
"Worksheet name already exists. Enter new name"
End If
Next wSht
Loop While wShtExists = True


'Following line adds sheet as first sheet
Sheets.Add Befo=Sheets(1)

'Following line adds sheet before active sheet
'Sheets.Add Befo=Sheets(oldShtName)

'Following line adds sheet after active sheet
'Sheets.Add After:=Sheets(oldShtName)

'Following line adds sheet after last sheet
'Sheets.Add After:=Sheets(Sheets.Count)

ActiveSheet.Name = newShtName
Sheets(oldShtName).Cells.Copy
Sheets(newShtName).Paste
Application.CutCopyMode = False
Range("A1").Select

End Sub

Regards,

OssieMac

"OssieMac" wrote:

Can be done. Where do you want the new sheets inserted? Before first sheet,
before or after the active sheet or at the end.

I assume that you want the user to be able to input a name for the sheet.
The system will be able to check if the name exists and if so, request
another name form the user.

Regards,

OssieMac

"JorgeG.ACT" wrote:

I wish to create a macro that basically creates a new tab and copies the
information from the old tab to the new tab.

The issue is that the tab names will vary between different users and the
number of tabs will increase regularly.

I have very limited experience with visual basic so every assistance would
be greatly appreciated.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch between worksheet tabs? LovelyKillerGal Excel Discussion (Misc queries) 3 May 2nd 07 01:55 AM
Is there a keyboard command to switch between tabs in Excel? Jen Excel Discussion (Misc queries) 2 February 17th 06 10:02 PM
How to switch between worksheet tabs on excel via keystroke shortc JohnK Excel Discussion (Misc queries) 2 January 26th 06 03:09 PM
Trying to switch to a different sheet in a macro? BigDave[_10_] Excel Programming 7 June 14th 05 06:44 PM
Macro : switch between excel and word Tom Excel Programming 4 November 19th 04 09:23 AM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"