I’m hoping this has a simple solution. I need to take values in from a worksheet, perform calculations and insert them into a hidden worksheet (to be uploaded later into a database). I don’t normally program in VBA, so I’m not sure what I’m doing wrong. My problem is this: when I copy data from the worksheet into the array, they are rounded like an integer when I’ve specified long. The following code snippet will give you an idea of the problem. Am I initializing the array wrong?
Dim ThisWS As Worksheet
Set ThisWS = Excel.ActiveWorkbook.Worksheets("BchSheet")
Dim BTW() As Long 'Beaker Tare Weight
ReDim Preserve BTW(Samples)
BTW(1) = ThisWS.Cells(18, 6).Value 'Value in cell is 98.7036
MsgBox (ThisWS.Cells(18, 6).Value) 'Returns 98.7036
MsgBox (BTW(1)) 'Returns 99
The
Longdata type, likeInteger, only holds whole numbers.Use the
Doubledata type to store decimals, or theCurrencydata type if you are working with calculations where fixed-point is necessary or you don’t want to deal with floating-point numbers.