Macro not working on all versions of Excel :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Macro not working on all versions of Excel
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

RWiles
Board Regular


Joined: 23 Apr 2003
Posts: 9
Location: Portland, OR
Flag: Usa

Status: Offline

 Reply with quote  

Macro not working on all versions of Excel

In the simple macro below, I use a button to copy some formulas and save as values. This works great in 2000. My problem is, the page is copied from a hidden page, and when I run in '97 the copied button is renamed and therefore has no code behind it. Is there a way to make this work on both versions?
icon_help.gif
Private Sub BudgCreate_Click()
Range("H10").Select
ActiveCell.FormulaR1C1 = "=R[-3]C[-4]"
Range("H11").Select
ActiveCell.FormulaR1C1 = "=R[1]C[-4]"
Range("H12").Select
ActiveCell.FormulaR1C1 = "=R[1]C[-5]"
Range("H10:H12").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("I16").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-5]/12"
Range("I16").Select
Selection.Copy
Range("I17:I51").Select
ActiveSheet.Paste
Range("I16:I51").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select

End Sub

Post Fri Sep 19, 2003 5:41 pm 
 View user's profile Send private message

Iridium
Board Master
Board Master


Joined: 16 Jul 2002
Posts: 2581
Location: Walsall, England
Flag: England

Status: Offline

 Reply with quote  

Re: Macro not working on all versions of Excel

VBA is still a bit of a black art to me but one thing I've learnt is that you don't need to select - the code you have is generated by the recorder probably so this is just an aside. You can make the code more efficient with changes to avoid selecting, for example

Range("A1:B4").Select
Selection.Copy

change to

Range("A1:B4").Copy

Doesn't answer your question though I know...
_________________

Post Fri Sep 19, 2003 5:56 pm 
 View user's profile Send private message

pennysaver
Board Master


Joined: 15 May 2003
Posts: 2189
Location: San Diego, California
Flag: Usa

Status: Offline

 Reply with quote  

Re: Macro not working on all versions of Excel


quote:

My problem is, the page is copied from a hidden page, and when I run in '97 the copied button is renamed and therefore has no code behind it. Is there a way to make this work on both versions?


From this, it's not really clear why your macro isn't working. And why is the button renamed in '97?

As an addition to Iridium's post, you can clean your code a bit more by only using Application.CutCopyMode = False once, at the end.

Hope that helps,

Smitty

Post Fri Sep 19, 2003 6:04 pm 
 View user's profile Send private message Visit poster's website MSN Messenger

RWiles
Board Regular


Joined: 23 Apr 2003
Posts: 9
Location: Portland, OR
Flag: Usa

Status: Offline

 Reply with quote  

Re: Macro not working on all versions of Excel

Thanks for the code suggestions, I was working on just getting the button to work before cleaning it up, I know that it is pretty bad right now.

I wish that I knew why the button is being renamed, after '97 copies the sheet the button becomes CommandButton1_Click. Is there anyway that I can get around this?

Post Fri Sep 19, 2003 6:17 pm 
 View user's profile Send private message

Ivan F Moala
MrExcel MVP


Joined: 11 Feb 2002
Posts: 3210
Location: Auckland, New Zealand
Flag: Newzealand

Status: Offline

 Reply with quote  

Re: Macro not working on all versions of Excel

quote:
Originally posted by RWiles:
Thanks for the code suggestions, I was working on just getting the button to work before cleaning it up, I know that it is pretty bad right now.

I wish that I knew why the button is being renamed, after '97 copies the sheet the button becomes CommandButton1_Click. Is there anyway that I can get around this?


It appears you are using an ActiveX control button [Control Toolbox] ?
How are you copyiing the Hidden sheet over ??

BTW, you can condense/clean code to

code:

Private Sub BudgCreate_Click()
Range("H10").FormulaR1C1 = "=R[-3]C[-4]"
Range("H11").FormulaR1C1 = "=R[1]C[-4]"
Range("H12").FormulaR1C1 = "=R[1]C[-5]"

With Range("H10:H12")
    .Copy
    .PasteSpecial Paste:=xlValues
End With

With Range("I16")
    .FormulaR1C1 = "=RC[-5]/12"
    .Copy
End With

With Range("I17:I51")
    .PasteSpecial xlPasteAll
    .Copy
    .PasteSpecial xlPasteValues
End With

Application.CutCopyMode = False
Range("A1").Select

End Sub



_________________
Kind Regards,
Ivan F Moala From the City of Sails

Post Fri Sep 19, 2003 6:53 pm 
 View user's profile Send private message Send e-mail Visit poster's website

RWiles
Board Regular


Joined: 23 Apr 2003
Posts: 9
Location: Portland, OR
Flag: Usa

Status: Offline

 Reply with quote  

Re: Macro not working on all versions of Excel

I am unhiding, copying and then re-hiding the sheet. I could actually leave the sheet visable, just trying to eliminate temptation for our field users. The entry that it creates will actually only be used by high level users so I am thinking about just noting that it will not work on '97, they should all have 2000 anyway.

Thanks for the tip on styles, I will definetely use them.

Post Fri Sep 19, 2003 7:10 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.