简体   繁体   中英

How would I convert this excel formula into a MS Access or VBA?

Trying to convert this MS Excel formula

=IF((D2+C3)>0,0,(D2+C3))

How would I convert it into MS Access or VBA?

This is the dataset table in Excel that we are importing into Access

在此处输入图片说明

Try something like this:

=IIF(([Rollover]+[Bucket])>0,0,([Rollover]+[Bucket]))

Although, your Excel formula references D2 and C3, in different rows. That's going to be a bit tricky in Access if that's what you really need to do. It is possible to do, if that's what you really want, but you may need to add a ROW Number field (or an autonumber ID field) in order to do that.

Blair

Editted: (since I just read the "see more comments")

The quick and dirty way to do this is to add the RowNumber field, the make a query from the dataset with a calculated field output NextRowNumber: [RowNumber]+1. Link the query and the dataset together with RowNumber and NextRowNumber. Use the [Rollover] field from the query ([Query]![Rollover] and the [Bucket] field from the dataset ([dataset]![Bucket]) in the equation above.

There is likely a more elegant way to do this in VBA, but the linked query / dataset should work.

Blair

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM