![]() |
Copy Unknown Number of Sheets
I have a Macro that prompts the user for a number. The program should then
insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
Copy Unknown Number of Sheets
Sub CopySheets()
Dim PhaseNum As Long Dim Count As Long Dim MinVal As Long Dim MaxVal As Long Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub -- Regards, Tom Ogilvy "Anice" wrote: I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
disable warning
Hello to the list,
I created some vba code in a workbook. i now do not want to use the code as some of the folks will not lower thier security settings. After deleting all the code and checking that there are no macros, i am still being asked to either enable or disale macros. How can i get rid of this message? thx, bob |
Copy Unknown Number of Sheets
I tried both of those, and the program is still stopping after:
Sheets("Input").Copy after:=Sheets("Input") It doesn't go to End Sub or give me an error. The program just stops. Any other suggestions?? Thank you for your advice "Don Guillett" wrote: would this be easier? Sub addsheets() On Error GoTo bye For i = InputBox("Number needed?") To 1 Step -1 Sheets("Input").Copy after:=Sheets("Input") ActiveSheet.Name = "Input" & i Next i bye: End Sub -- Don Guillett SalesAid Software "Anice" wrote in message ... I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
Copy Unknown Number of Sheets
In contrast, the corrected code I posted ran perfectly for me.
try creating a new blank workbook. Name the first sheet Input. Put your code in a general module (insert=Module). then run it with this workbook the activeworkbook. It should work. If it does, then the question is why it doesn't work for in your original workbook. My guess would be that you have a user defined function written in VBA in the INPUT sheet that raises an error when you copy the sheet and causes your macro execution to halt. -- Regards, Tom Ogilvy "Anice" wrote: I tried both of those, and the program is still stopping after: Sheets("Input").Copy after:=Sheets("Input") It doesn't go to End Sub or give me an error. The program just stops. Any other suggestions?? Thank you for your advice "Don Guillett" wrote: would this be easier? Sub addsheets() On Error GoTo bye For i = InputBox("Number needed?") To 1 Step -1 Sheets("Input").Copy after:=Sheets("Input") ActiveSheet.Name = "Input" & i Next i bye: End Sub -- Don Guillett SalesAid Software "Anice" wrote in message ... I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
Copy Unknown Number of Sheets
or
Input has a space before or after. -- Don Guillett SalesAid Software "Tom Ogilvy" wrote in message ... In contrast, the corrected code I posted ran perfectly for me. try creating a new blank workbook. Name the first sheet Input. Put your code in a general module (insert=Module). then run it with this workbook the activeworkbook. It should work. If it does, then the question is why it doesn't work for in your original workbook. My guess would be that you have a user defined function written in VBA in the INPUT sheet that raises an error when you copy the sheet and causes your macro execution to halt. -- Regards, Tom Ogilvy "Anice" wrote: I tried both of those, and the program is still stopping after: Sheets("Input").Copy after:=Sheets("Input") It doesn't go to End Sub or give me an error. The program just stops. Any other suggestions?? Thank you for your advice "Don Guillett" wrote: would this be easier? Sub addsheets() On Error GoTo bye For i = InputBox("Number needed?") To 1 Step -1 Sheets("Input").Copy after:=Sheets("Input") ActiveSheet.Name = "Input" & i Next i bye: End Sub -- Don Guillett SalesAid Software "Anice" wrote in message ... I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
Copy Unknown Number of Sheets
Just to continue such a stimulating discussion (and I have nothing pressing
at the moment), to me, that would seem less likely since no error handler is shown and the OP stated no error is raised. Excel VBA has never been know to be stingy with popping up a subscript out of range error <g. Nonetheless, regardless of having espoused such wisdom in response to your eloquent suggestion, it costs little to check. -- Regards, Tom Ogilvy "Don Guillett" wrote: or Input has a space before or after. -- Don Guillett SalesAid Software "Tom Ogilvy" wrote in message ... In contrast, the corrected code I posted ran perfectly for me. try creating a new blank workbook. Name the first sheet Input. Put your code in a general module (insert=Module). then run it with this workbook the activeworkbook. It should work. If it does, then the question is why it doesn't work for in your original workbook. My guess would be that you have a user defined function written in VBA in the INPUT sheet that raises an error when you copy the sheet and causes your macro execution to halt. -- Regards, Tom Ogilvy "Anice" wrote: I tried both of those, and the program is still stopping after: Sheets("Input").Copy after:=Sheets("Input") It doesn't go to End Sub or give me an error. The program just stops. Any other suggestions?? Thank you for your advice "Don Guillett" wrote: would this be easier? Sub addsheets() On Error GoTo bye For i = InputBox("Number needed?") To 1 Step -1 Sheets("Input").Copy after:=Sheets("Input") ActiveSheet.Name = "Input" & i Next i bye: End Sub -- Don Guillett SalesAid Software "Anice" wrote in message ... I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
Copy Unknown Number of Sheets
Be nice Tom.
As we are all too aware, sometimes OPs don't tell us everything.... -- Don Guillett SalesAid Software "Tom Ogilvy" wrote in message ... Just to continue such a stimulating discussion (and I have nothing pressing at the moment), to me, that would seem less likely since no error handler is shown and the OP stated no error is raised. Excel VBA has never been know to be stingy with popping up a subscript out of range error <g. Nonetheless, regardless of having espoused such wisdom in response to your eloquent suggestion, it costs little to check. -- Regards, Tom Ogilvy "Don Guillett" wrote: or Input has a space before or after. -- Don Guillett SalesAid Software "Tom Ogilvy" wrote in message ... In contrast, the corrected code I posted ran perfectly for me. try creating a new blank workbook. Name the first sheet Input. Put your code in a general module (insert=Module). then run it with this workbook the activeworkbook. It should work. If it does, then the question is why it doesn't work for in your original workbook. My guess would be that you have a user defined function written in VBA in the INPUT sheet that raises an error when you copy the sheet and causes your macro execution to halt. -- Regards, Tom Ogilvy "Anice" wrote: I tried both of those, and the program is still stopping after: Sheets("Input").Copy after:=Sheets("Input") It doesn't go to End Sub or give me an error. The program just stops. Any other suggestions?? Thank you for your advice "Don Guillett" wrote: would this be easier? Sub addsheets() On Error GoTo bye For i = InputBox("Number needed?") To 1 Step -1 Sheets("Input").Copy after:=Sheets("Input") ActiveSheet.Name = "Input" & i Next i bye: End Sub -- Don Guillett SalesAid Software "Anice" wrote in message ... I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
Copy Unknown Number of Sheets
Thank you Tom. It didn't work in an empty workbook either, and there aren't
any extra spaces in the name. I think there may be another problem and it has nothing to do with the program that is written. At least if I was given an error I would have something more to go on. I may try running it on a coworkers computer and see if it works there. Thank you again for your time, I do appreciate it! I'm learning alot from you all! "Tom Ogilvy" wrote: In contrast, the corrected code I posted ran perfectly for me. try creating a new blank workbook. Name the first sheet Input. Put your code in a general module (insert=Module). then run it with this workbook the activeworkbook. It should work. If it does, then the question is why it doesn't work for in your original workbook. My guess would be that you have a user defined function written in VBA in the INPUT sheet that raises an error when you copy the sheet and causes your macro execution to halt. -- Regards, Tom Ogilvy "Anice" wrote: I tried both of those, and the program is still stopping after: Sheets("Input").Copy after:=Sheets("Input") It doesn't go to End Sub or give me an error. The program just stops. Any other suggestions?? Thank you for your advice "Don Guillett" wrote: would this be easier? Sub addsheets() On Error GoTo bye For i = InputBox("Number needed?") To 1 Step -1 Sheets("Input").Copy after:=Sheets("Input") ActiveSheet.Name = "Input" & i Next i bye: End Sub -- Don Guillett SalesAid Software "Anice" wrote in message ... I have a Macro that prompts the user for a number. The program should then insert a copy of an existing page that number of times. The program prompts the user, but then stops before inserting any new pages. Here is what I have right now. Thank you for all your help!! Sub CopySheets() Dim PhaseNum As Double Dim Count As Double Dim MinVal As Double Dim MaxVal As Double Dim Msg As String Dim UserEntry As String MinVal = 1 MaxVal = 20 Msg = "Enter the Number of Program Phases" Msg = Msg + vbNewLine Msg = Msg + "Between 1 and 20" Do UserEntry = InputBox(Msg) If UserEntry = "" Then Exit Sub If IsNumeric(UserEntry) Then PhaseNum = Val(UserEntry) If PhaseNum <= MaxVal And PhaseNum = MinVal Then Exit Do End If Loop For Count = 1 To PhaseNum Sheets("INPUT").Select Sheets("INPUT").Copy After:=Sheets("INPUT") Next Count End Sub |
All times are GMT +1. The time now is 02:53 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com