VBA for math using decimals

ed.ayers315

Board Regular
Joined
Dec 14, 2009
Messages
166
Hi Folks,

I have written the following code to calculate the results in other textboxes. This works fine until I start with a decimal point.

If I start entering with a 0 then the decimal it still works.

So I have two questions:

1) Is there a way to allow the user to start with a decimal i.e. (.11) or will they have to type (0.11)?

2) Is there a way to keep the data in the cells after the form is closed. The results are still in the workbook cells and I would like them to stay visable when reopening the form until the worksheet is cleared?

Here is the Code:

[Private Sub TB45A_Change()
ActiveSheet.Unprotect
TB45B.Value = Application.WorksheetFunction.VLookup(Range("I13"), [SELF_CONTAINED_DATA], 14, 0) & " PPM"
TB46B.Value = Application.WorksheetFunction.VLookup(Range("I13"), [SELF_CONTAINED_DATA], 15, 0) & " PPM"
TB46A.Value = Round(CDbl(TB45A.Value) / 128 * 1000000, 0) & " PPM"


End Sub]

Thanks for any help
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try something like this...

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] TB45A_Change()
    
    [COLOR=darkblue]If[/COLOR] IsNumeric(TB45A.Value) [COLOR=darkblue]Then[/COLOR]
        ActiveSheet.Unprotect
        TB45B.Value = Application.WorksheetFunction.VLookup(Range("I13"), [SELF_CONTAINED_DATA], 14, 0) & " PPM"
        TB46B.Value = Application.WorksheetFunction.VLookup(Range("I13"), [SELF_CONTAINED_DATA], 15, 0) & " PPM"
        TB46A.Value = Round(CDbl(TB45A.Value) / 128 * 1000000, 0) & " PPM"
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

I don't understand #2. Which cells? You can populate the textboxes when you open the userform by using the UserForm_Initialize procedure.
Example:
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] UserForm_Initialize()
    TB45B.Value = Sheets("Sheet1").Range("A1").Value
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,206,762
Messages
6,074,792
Members
446,089
Latest member
Andrew123456789

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