Solved

On Open Event Macro To Run Code

Posted on 2013-01-19
12
201 Views
Last Modified: 2013-01-26
Hello Experts,

I am currently using this code (in a module),...

Sub ClearMeasuringUp()
    If MsgBox("You are about to clear the entire worksheet - Are you sure you want to proceed?", vbYesNo) = vbYes Then
        ActiveSheet.Range("B28:D28,F28:H28,J28:L28,P28").ClearContents
        ActiveSheet.Cells(27, 14).Value = "Diameter"
        Application.Goto Reference:="Diameter"
        Selection.ClearContents
    End If
End Sub

Open in new window


I would also like to run this code,...

ActiveSheet.Cells(27, 14).Value = "Diameter"

Open in new window


When the workbook is opened.

Thank you in advance for your help!

~ Geekamo
0
Comment
Question by:Geekamo
  • 4
  • 4
  • 3
12 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
In the WORKBOOK module place it within

Private Sub Workbook_Open()

End Sub
0
 
LVL 1

Author Comment

by:Geekamo
Comment Utility
@ ssaqibh,

Thank you for the piece of code (The points are already yours).  But as I was just about to place the code in, I realized I have a problem.  The code I though I could reuse, I don't think I can.

When this code is run, via the user running the code - it's fine. Cause they are running the code specific to that page.

ActiveSheet.Cells(27, 14).Value = "Diameter",

I also want that code to run on open, but I realized it only calls the "ActiveSheet", and technically it's going to run on the active sheet.

So I guess my code needs to be revised further to fix this?  The name of the page is called "Measuring Up".  Idk, if the new code would need to know that.

I hope I didn't confuse things further. I just barely grasp this!  :)

~ Geekamo
0
 
LVL 45

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
Comment Utility
Except that the active sheet may not be the one you want so

Private Sub Workbook_Open()

' Sheet1 should be change to the name of your sheet
Sheets("Sheet1").Cells(27, 14).Value = "Diameter"

End Sub

Open in new window


is probably better better.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 250 total points
Comment Utility
"Measuring Up"

Private Sub Workbook_Open()
Sheets("Measuring Up").range("N27") = "Diameter"
End Sub
0
 
LVL 1

Author Comment

by:Geekamo
Comment Utility
Thank you!

~ Geekamo
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
@ssaqibh: Was there any reason why my answer in post ID 38797727 didn't get at least partial credit?
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
The only reason I can think of is that you did not use the sheet reference requested by Geekamo....otherwise it was just fine.
0
 
LVL 1

Author Comment

by:Geekamo
Comment Utility
@ MartinLiss,

When I came back to this thread, I saw both answers.  I basically picked the one I was more comfortable with which was "ssaqibh" answer because it references ("N27") instead of (27, 14).  I know my answer did include, (27, 14) - but anytime I can see the cell itself in the code - the easier it is for me to read through it and understand what's going on.

Now, none of that even matters because you are correct.  Had I given this post more thought when I was selecting where the points were going - I should have selected yours, or at the very least divided the points between you both.

@ All

I am willing to make the request for all points be given to MartinLiss, or at least have the points divided evenly between you both. If either of you don't mind, please respond with who should get the points, or how they should be divided up.

Thanks!

~ Geekamo
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I'm happy with a 50/50 split.
0
 
LVL 1

Author Comment

by:Geekamo
Comment Utility
@ All,

Thanks again!

~ Geekamo
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now