Defining a variable correctly

Posted on 2014-03-29
Last Modified: 2014-03-29
I have a calculated value of .5226789654. However, I only need to check .5226 and my feeble attempts below are failing:

Dim Gender As Double
Gender = 0.5226
Selection.NumberFormat = ".####"
If Range("E4").Value <> Gender Then
    MsgBox "Male % between 0-4 is wrong!", vbExclamation, "Wrong Percentage!"
     Exit Sub
 End If

Open in new window

Question by:Frank Freese
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 45

Accepted Solution

aikimark earned 500 total points
ID: 39964167
Use currency data type
Dim Gender As Currency

Open in new window


Author Comment

by:Frank Freese
ID: 39964179
It's not currency but a percent

Author Comment

by:Frank Freese
ID: 39964262
currency seemed to work

Author Closing Comment

by:Frank Freese
ID: 39964263
thank you

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
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…

726 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