Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro works once, not twice

I created a macro that sits on a worksheet(A), when run, it unhides
worksheet(B) and makes a copy of worksheet(B) prompting the user to
name the new worksheet(C). This works well. Part two of the process
includes a button on worksheet(C) that references the same macro on
worksheet(A). Clicking the button on worksheet(C) gives me a
"run-time error 1004" asking if I would like to debug. Debugging tags
this line in the macro:

Sheets("Earnings Code").Select

Full macro looks like this:

Sub NewEarningsCodeSheet()
Call UnhideEarningsCode
Sheets("Earnings Code").Select
shName = Application.InputBox("Enter The Name of the New Earnings
Code", "Delphia Consulting")
If (shName = False) Or shName = "" Then Exit Sub

Sheets("Earnings Code").Copy After:=Sheets(4)
ActiveSheet.Name = shName


End Sub

What am I doing wrong? It seems like it can only copy the worksheet
once or that it is trying to find it in a different location. I
appreciate any help, as I am somewhat new to this. Fun though.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro works once, not twice

What's the code for 'UnhideEarningsCode'

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro works once, not twice

What's the code for 'UnhideEarningsCode'

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro works once, not twice


Sub UnhideEarningsCode()

Sheets("Earnings Code").Visible = True

Worksheets("Earnings Code Setup Document").Activate

End Sub



Sorry I didn't include that before. Thanks.


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro works once, not twice

Sorry code is actually

Sub UnhideEarningsCode()

Sheets("Earnings Code").Visible = True

Worksheets("Earnings Code").Activate

End Sub


Didn't change anything. Macro will run multiple time from the origianl
worksheet, but will not run from the button on the newly created
worksheet.



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro works once, not twice

This isn't a fix; just some information to consider in the meantime
You've use Sheet("Sheetname") to access your different worksheets. yo
should refer to them by their sheet name instead. It makes for a lo
less code to write in the long run. While in the VBA editor, selec
view, then project explorer (if its not already visible. It's th
window in the top-left corner of the window. Under Microsoft Exce
Objects, you'll see each sheet, first, by it's name and then, i
parenthesis, it's sheet number.
i.e. MySheetName (Sheet 1).
When accessing the sheet within your code, you can us
*Sheet1.function* as opposed to *Sheets("MySheetName").function*.

I'll keep storming through a solution to your problem.

-Gitcyphe

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro works once, not twice



Thanks for the help. Much appreciated. Got it to work with the
following but it becomes slower each time the macro runs. Since the
macro runs fine the first time from the first worksheet, I modified the
macro to mae that sheet active first and then unhide the other sheet to
copy. It works just not well. Thanks again

Sub NewEarningsCodeSheetCopy()
Worksheets("Table of Contents").Activate
Call UnhideEarningsCode
Sheets("Earnings Code").Select
shName = Application.InputBox("Enter The Name of the New Earnings
Code", "Delphia Consulting")
If (shName = False) Or shName = "" Then Exit Sub

Sheets("Earnings Code").Copy After:=Sheets(4)
ActiveSheet.Name = shName


End Sub



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
Email Macro only sometime works? PaulW Excel Discussion (Misc queries) 0 August 15th 06 10:22 AM
macro works separately but not together... Gbiwan Excel Programming 4 February 18th 04 03:44 AM
Macro works from RUN but not from shortcut Joe Pyrdek Excel Programming 1 November 29th 03 03:53 PM
macro works in .xlt but not .xls BrianG[_3_] Excel Programming 6 September 18th 03 10:13 PM


All times are GMT +1. The time now is 05:58 AM.

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

About Us

"It's about Microsoft Excel"