Solved

Formula in worksheet.activate

Posted on 2013-12-09
8
113 Views
Last Modified: 2013-12-09
Folks,
I have a need to automatically enter into a cell a formula when the worksheet is activated.
This did not work:
ActiveSheet.Range("C6").Select
Range("C6") = B6 / A6

Open in new window

Once I have place to formula in the cell I need NOT to display it.
I've been using this code for to accomplish that:
Selection.NumberFormat = ";;;"

Open in new window


What is the correct coding I should use since the first failed bit of code failed.
0
Comment
Question by:Frank Freese
  • 4
  • 4
8 Comments
 
LVL 45

Assisted Solution

by:Martin Liss
Martin Liss earned 500 total points
ID: 39706920
Range("C6").Formula = "=B6 / A6"
0
 
LVL 45

Assisted Solution

by:Martin Liss
Martin Liss earned 500 total points
ID: 39706931
Please see this answer for two other ways to hide the formula.
0
 

Author Comment

by:Frank Freese
ID: 39706990
Almost there...
The value returned from the formula generates an ISERROR, which is what it is suppose to do.
I was hoping that I could apply the Select.NumberFormat=";;;" to hide the ISERROR display but that did not work.
When the worksheet is activated I do want to maintain the formulas, even with ISERROR but only display them when the user clicks on the "Display Data" command box.
This is a lesson on ISERROR on that workbook I've been working on.
0
 

Author Comment

by:Frank Freese
ID: 39707041
I could use conditional formatting and havew the font color white?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39707042
Try this formula instead
Range("C6").Formula = "=IF(ISERROR(B6 / A6),"" "",B6 / A6)"
0
 

Author Closing Comment

by:Frank Freese
ID: 39707152
You nailed it
Good job and many thanks
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 39707174
You're welcome and I'm glad I was able to help. Do you understand what the modified formula is doing?

Marty - MVP 2009 to 2013
0
 

Author Comment

by:Frank Freese
ID: 39707332
Yes I do understand.
If the formula generates an ISERROR then print "", else the solution.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

760 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

19 Experts available now in Live!

Get 1:1 Help Now