+ Reply to Thread
Results 1 to 5 of 5

Formatting Data in VBA

  1. #1
    Registered User
    Join Date
    08-04-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    41

    Formatting Data in VBA

    In my workbook, cells(16,6) =0.001502


    The code below is returning curr_price=1.50160245635267E-03

    I need the code to return 0.001502

    Any suggestions would be greatly appreciated!

    My code is as below

    Private Sub lb_disc_Click()
    Dim mcounter As Integer
    Dim curr_price As Double

    select_tx_dis.Value = lb_disc.Value
    Worksheets("1. Discount Fees").Select
    Set Z = ThisWorkbook
    For mcounter = 1 To 19 Step 1
    If Cells(mcounter + 15, 1) = lb_disc.Value Then
    curr_price = Cells(mcounter + 15, 6)

    End If
    Next mcounter
    tx_current_price = curr_price

    End Sub

    Kindly help me.
    Last edited by somani123; 12-12-2014 at 12:54 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,375

    Re: Formatting Data to 2 Decimal Places in VBA

    facility_1 is dimensioned as an integer, which can only store integers (no fractions/decimals). If you need fraction/decimal data, you need to dimension your variable as double, not integer.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    08-04-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    41

    Re: Formatting Data in VBA

    In short the double value is converting to scientific format.

    How can i get the value in double only?

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,375

    Re: Formatting Data in VBA

    this forum can be pretty strict about putting code inside of code tags. Refer here: http://www.excelforum.com/forum-rule...rum-rules.html for instructions on using code tags.

    Other than rounding, your code is returning the correct value is it not? Do you need a =ROUND() function in cells(16,6) before running this code (=ROUND(current cell formula,6)?

  5. #5
    Registered User
    Join Date
    08-04-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    41

    Re: Formatting Data in VBA

    Thanks for ur help. It is working as expected.

    Thanks a lot.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. formatting of a cell to 2 decimal places
    By JohnD0e in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-02-2010, 11:11 PM
  2. conditional formatting for 0 in 2 decimal places
    By mingali in forum Excel General
    Replies: 11
    Last Post: 02-27-2010, 05:34 AM
  3. Formatting decimal places
    By thetallguy0 in forum Excel General
    Replies: 2
    Last Post: 03-04-2008, 09:03 AM
  4. conditonally formatting decimal places
    By BigMikeGallagher in forum Excel General
    Replies: 0
    Last Post: 04-06-2006, 01:10 PM
  5. Formatting Currenty - decimal places
    By JTF in forum Excel General
    Replies: 2
    Last Post: 07-21-2005, 02:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1