In order to set the value of a specific cell when
exporting to Excel, you must know the number of the row
and the column for each cell that will contain data. To do
this, you cannot use DoCmd.TransferSpreadsheet - you
actually have to open an instance of Excel from within the
function (it's your choice whether to make it visible or
not), and then dump data into the worksheet wherever you
need it.
The format when setting Cell values is .Cells(Row,
Column).Value =
So for example, to dump data into a new worksheet:
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
With xlSheet
.Cells(1, 1).Value = "I am in Row 1, Column A"
.Cells(3,3).Value = "I am in Row 3, Column C"
.....and so on, filling in the cells
End With
I do this by pulling data from a query and then setting
the various data points into specific cells on the screen.
Helpful hint - if you want to include any formulas or
formatting, go to a blank Excel worksheet, start recording
a Macro, and then do the formula or formatting in the
worksheet. Once you've done that formatting, stop the
Macro, then open it and you'll see the VBA to use from
within the VBA in your Access function.