Writing VBA code for Excel Spreadsheets

Copper Contributor

Hello, I am writing a code in vba for an excel spreadsheet that takes an array of dates for a particular sheet, and iterates through the array for each row of the sheet. If the code finds the the date on the row matches a date in the array, it will input into the row the price that is listed in a parallel array. The code works fine, but every time the code inputs a price with decimal places, the decimal places are eliminated. It is not rounding because if a price is put in as, for example, 2214.5, the sheet will read 2214. I included the whole code, but I sent a snip of  the loop that interates and inputs. I also included a snip of the sheet, to show that it is doing what I say it is doing. I thought it might be a data type issue, so I changed all of my arrays from integers to longs, but that didn't work. Also, it doesn't show the full number in the formula bar if I click on the cell, it just simply inputs the wrong value. What can I do to resolve this?

1 Reply
Changing the price amount array data type from integer to long won't fix the problem (long is still an integer). You need to use a data type for the array containing price amounts that supports decimals, such as single or double.