I have a vba macro that takes data from one workbook and pastes it into another workbook. In doing this I have declared a few variables of type single (I only need two decimal precision). However, when I copy the values from the cells on the source workbook and paste them into the target workbook, the numbers end up having 12 decimal places. Ultimately, this extra precision causes my totals to be off by .01 or more after a while. I have tried rounding the number as I pull it off the source workbook into the variable, but that didn't matter. How do I solve this problem?
Code for pulling data from source workbook:
Select Case product_class
Case 1
lbs_of_product_cl1 = Round(lbs_of_product_cl1 + Selection.Value, 2)
Selection.Offset(0, 4).Select
butterfat_cl1 = Round(butterfat_cl1 + Selection.Value, 2)
Case 2
lbs_of_product_cl2 = Round(lbs_of_product_cl2 + Selection.Value, 2)
Selection.Offset(0, 4).Select
butterfat_cl2 = Round(butterfat_cl2 + Selection.Value, 2)
End Select
code for pasting the data into the target workbook:
Selection.Value = lbs_of_product_cl1
Selection.Offset(0, 1).Select
Selection.Value = butterfat_cl1
Selection.Offset(0, 1).Select
Selection.Value = lbs_of_product_cl2
Selection.Offset(0, 1).Select
Selection.Value = butterfat_cl2
Thanks
Bookmarks