Solved

Formula in worksheet.activate

Posted on 2013-12-09
8
131 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 46

Assisted Solution

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

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:Frank Freese
ID: 39707041
I could use conditional formatting and havew the font color white?
0
 
LVL 46

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 46

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

770 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