how to write excel vba formula into R

Try CSV export

I'm sorry. I can't make out anything from that images, and images in general. Exporting the example rows to csv and then sharing in some fashion that could be read in or at least be copy pasted would be good.

Some convenient sites for sharing code and data are:

If the above are unavailable, a last resort would putting the data in a post in this thread. At least plain text is a bit more tractable than images.

Read data into R and emit as a reproducible example

See this post for details about how to make reproducible examples. In short, some R code that gets the readers to the starting point of the problem is the most likely to get a useful answer.