Creating a formula to put in a spreadsheet created with


Okay, I have the following For loop, and I need to calculate the following value, but I don't have a clue...

What I want is:

K4 = ( H4 - ( I4 + J4 ) )
K5 = ( H5 - ( I5 + J5 ) )
K6 = ( H6 - ( I6 + J6 ) )
K7 = ( H7 - ( I7 + J7 ) )
K26 = ( H26 - ( I26 + J26 ) )


Number of Cars = 23
I Column has an integer value of 8
H Column has an integer value of 9
J Column has an integer value of 10
K Column has an integer value of 11

Now here is the for loop

        CarNumberPositionCounter = 0
        For CheckAmountCounter As Integer = 1 To NumberOfCars

            CellRow = 3 + CheckAmountCounter
            Dim CellColumn2 As Integer = 11

            oSheet.Cells(CellRow, CellColumn2).Value = (oSheet.Cells(CellRow, 8) - (oSheet.Cells(CellRow, 9) + oSheet.Cells(CellRow, 10))) 'This doesn't work, but you get the idea
            CheckAmountCounter += 1

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

did u try it by including the value property

oSheet.Cells(CellRow, 8).Value - (oSheet.Cells(CellRow,9).Value + oSheet.Cells(CellRow, 10).Value)

Bob LearnedCommented:
Wouldn't it be just as effective to let Excel do that, with a formula in a cell?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
indy500fanAuthor Commented:

I think this is what you are talking about...

        oRng = oSheet.Range("K4", "K" & NumberOfCars + 3)
        oRng.Formula = "=H4 - (I4+J4)"

This is what I used to make it work...

bchoor, I didn't try it because I figured out the solution above, but...If you think it'll work, I'll give you the points.

indy500fanAuthor Commented:
Since you guys responded, but I haven't heard back I'll split the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.