Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

reference to macro button is lost

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Excel-General - 17 Jan 2008 21:56 GMT
I had this macro in a workbook attached to a button on sheet1.
Sub months()
   'count the number of worksheets
   Sheets(1).Select
   n = Worksheets.Count + 1
   i = 2
   ' Skip the first worksheet - it's the controls sheet
   Text = Range("D3")
   Do
       Sheets(i).Select

       Range("V6").Select
       ActiveCell.FormulaR1C1 = Text
       i = i + 1
   Loop Until i = n
End Sub

It goes to the 2nd sheet and changes a date.  This macro worked fine
until I added a userform now this macro button doesn't work.  It now
says the variables are undefined.  Well they are undefined but they
worked before.  I just want to know the reason why?  The macro is in
module 1.    The command button code is simple.
Public Sub CommandButton1_Click()
months
End Sub

So this sheet object with the button on can't find the module because
it doesn't know to look in both the module and the userform?   The
userform macro is called from sheet1 as well.  Just trying to
understand the process
tnx,

Is the reason because of adding the userform now this button doesn't
know how to find the months macro in the module?  It could find it
before.  NOthing is really changed except for adding a userform.
tnx,
Don Guillett - 17 Jan 2008 22:57 GMT
You had to DIM your variables. See the 3 lines at the top of your macro.
========
HOWEVER, she my shorter, without selection macro
Sub months1()
Dim i As Long
For i = 2 To Worksheets.count
Sheets(i).Range("v6") = Range("d3")
Next i
End Sub
=======
Sub months()
Dim n As Long
Dim i As Long
Dim text

   'count the number of worksheets
   Sheets(1).Select
   n = Worksheets.count + 1
   i = 2
   ' Skip the first worksheet - it's the controls sheet
   text = Range("D3")
   Do
       Sheets(i).Select

       Range("V6").Select
      MsgBox ActiveCell
       ActiveCell.FormulaR1C1 = text
       i = i + 1
   Loop Until i = n
End Sub

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

>I had this macro in a workbook attached to a button on sheet1.
> Sub months()
[quoted text clipped - 32 lines]
> before.  NOthing is really changed except for adding a userform.
> tnx,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.