+ Reply to Thread
Results 1 to 3 of 3

Passing in values

Hybrid View

froggy19 Passing in values 07-19-2007, 03:38 AM
froggy19 Hi, i realise the problem... 07-19-2007, 04:41 AM
mudraker Step 1 is to declare your... 07-19-2007, 08:33 AM
  1. #1
    Registered User
    Join Date
    06-26-2007
    Posts
    36

    Passing in values

    Hi,

    i have attached parts of my code which is not doing properly as i am not sure which part of it is wrong.
    Sub Histogram(YearFrom, YearTo, ET, BL)
    
    Dim lastrowBis, rowBis, ff, fi, YF, YT, fo As Long
    Dim netlossamtis As Currency
    
    lastrowBis = 0
        lastrowBis = ActiveWorkbook.Sheets("Data").UsedRange.Rows.Count
    
        For rowBis = 2 To lastrowBis
        
    fi = (YearTo - YearFrom) + 1
    fo = ActiveWorkbook.Sheets("Data").Cells(rowBis, 12).Value
    ff = (fo * fi) 'suppose to multiply fo and fi
            
    netlossamtis = ActiveWorkbook.Sheets("Data").Cells(rowBis, 13).Value
                    
            Select Case netlossamtis
                Case 0.01 To 1000#
                    a = a + ff
                Case 1000.01 To 2000#
                    b = b + ff
                Case 2000.01 To 3000#
                    c = c + ff
                Case 3000.01 To 4000#
                    d = d + ff
    ........ End Select... 
    ........ Next rowBis...
    It does not seems to be able to calculate ff

    http://www.mrexcel.com/board2/viewto...364790#1364790
    Last edited by froggy19; 07-19-2007 at 03:47 AM.

  2. #2
    Registered User
    Join Date
    06-26-2007
    Posts
    36
    Hi,

    i realise the problem only happens when the values in my worksheet "Data" is too small such that when the multiplication is done, the value is rounded to nearest integer so when my value is 0.01 etc, when multiplication is done, the answer i get will be 0. But when my value is 1, i get the exact answer. Is it possible for me to set in Excel vba to accept digits with decimal places and not have them round to nearest integer?

    Thank you.

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Step 1 is to declare your variables correctly

    In your code
    Dim lastrowBis, rowBis, ff, fi, YF, YT, fo As Long
    Only fo is declared as long type all others are variable types.
    Long type can not hold decimal numbers. Use Double type

    To declare variables correctly you must have variable name followed by As Type

    example
    Dim lastrowBis As Long, rowBis As Long, ff As Double
    or

    Dim lastrowBis As Long
    Dim rowBis As Long
    Dim ff As Double
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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