I see. Yeah my version is probably a bit more efficient. The other bit I would try to optimize is the lookup of the Text variable, with some sort of dictionary acting as a cache - so that we do the actual lookup only once. Roughly:
' outside the loop.
Dim AccTextCache as new Dictionary(Of Integer, String)
For each cell in yourBuffer
' If you've not filtered your buffer already to contain only interesting cells,
' do your work here, then...
' try to get text from cache
Dim accText as String = AccTextCache.XFGetValue(cell.DataBufferCellPK.AccountID, Nothing)
if accText is Nothing then
' not found in cache, need to look it up ...
' note: prefer api. methods over brapi. ones, they are faster
accText = api.Account.Text(cell.DataBufferCellPK.AccountID, 6, scenarioTypeId, timeId)
' ... then store it in our cache
AccTextCache.Add(cell.DataBufferCellPK.AccountID, accText)
end if
' rest of the work here
next
... but the value of this effort may or may not be significant, only benchmarking would tell.
I'd also try to get rid of any call to .GetAccountName and similar. Stick to IDs everywhere.