Finding a number with 2 decimal places

shah0101

Board Regular
Joined
Jul 4, 2019
Messages
118
Hi Experts,

I have a value in C10 (say 37,313.58) which is fixed.

In B10 & B11 are Prices which can be changed
In A10 is A11 Quantity which can be changed

I need a formula / vba script to get exact two decimal place number (not rounded, not truncated) in:
(1) "B10" (range from 0.84 to 6.00) wholly divisible by "C10" by "A10"
(2) "B11" (range from 12.00 to 30.00) wholly divisible by "C11 by A11"


How we can find an exact two decimal places number by automatically change the number either in B10/B11 or A10/A11 to get the final number as in C10 (which is basically A10 * B10 or A11 * B11).


I don't know if I am making any sense! so uploaded a picture.
 

Attachments

  • 001.jpg
    001.jpg
    42.8 KB · Views: 11

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
With C10 contants giving value
From A13:F13 downward will be list of Qty & Price for 3 cases: whole qty, 1 decimal and 1-2 decimal
VBA Code:
Option Explicit
Sub test()
Dim i&, k&, arr()
Dim StartP As Double, MaxP As Double, Value As Double, Sp As Double, NewP  As Double, NewQ  As Double
Value = Range("c10").Value
StartP = 0.84'Start Price
MaxP = 6 ' Max Price
Sp = 0.01 ' Step Price
ReDim arr(1 To 200000, 1 To 6)
    Do
        i = i + 1
        NewP = StartP + (i - 1) * 0.01
        NewQ = Value / NewP
        If Int(NewQ * 100) = NewQ * 100 Then
            k = k + 1
            arr(k, 5) = NewQ: arr(k, 6) = NewP
            If Int(NewQ * 10) = NewQ * 10 Then
               arr(k, 3) = NewQ: arr(k, 4) = NewP
               If Int(NewQ) = NewQ Then
                    arr(k, 1) = NewQ: arr(k, 2) = NewP
               End If
            End If
        End If
    Loop Until NewP > MaxP
Range("A13").Resize(200000, 6).ClearContents
Range("A13").Resize(k, 6).Value = arr
End Sub
1652927764726.png
 
Upvote 0
With C10 contants giving value
From A13:F13 downward will be list of Qty & Price for 3 cases: whole qty, 1 decimal and 1-2 decimal
VBA Code:
Option Explicit
Sub test()
Dim i&, k&, arr()
Dim StartP As Double, MaxP As Double, Value As Double, Sp As Double, NewP  As Double, NewQ  As Double
Value = Range("c10").Value
StartP = 0.84'Start Price
MaxP = 6 ' Max Price
Sp = 0.01 ' Step Price
ReDim arr(1 To 200000, 1 To 6)
    Do
        i = i + 1
        NewP = StartP + (i - 1) * 0.01
        NewQ = Value / NewP
        If Int(NewQ * 100) = NewQ * 100 Then
            k = k + 1
            arr(k, 5) = NewQ: arr(k, 6) = NewP
            If Int(NewQ * 10) = NewQ * 10 Then
               arr(k, 3) = NewQ: arr(k, 4) = NewP
               If Int(NewQ) = NewQ Then
                    arr(k, 1) = NewQ: arr(k, 2) = NewP
               End If
            End If
        End If
    Loop Until NewP > MaxP
Range("A13").Resize(200000, 6).ClearContents
Range("A13").Resize(k, 6).Value = arr
End Sub
View attachment 65005

Thank you very much for your time and efforts to help.

I think I am doing something wrong because after executing the macro, it doesn't bring any results. Sharing screenshots. I just changed the name to "PriceCalc".

Please advise.
 

Attachments

  • 001.jpg
    001.jpg
    202.5 KB · Views: 4
  • 003.jpg
    003.jpg
    128.7 KB · Views: 4
Upvote 0

Forum statistics

Threads
1,215,230
Messages
6,123,752
Members
449,118
Latest member
kingjet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top