Creating a formula to put in a spreadsheet created with VB.net

Friends

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 ) )

Known:

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

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

Bob
0
 
bchoorCommented:
did u try it by including the value property

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

HTH
~BC
0
 
indy500fanAuthor Commented:
Bob,

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.

Regards,
Eric
0
 
indy500fanAuthor Commented:
Since you guys responded, but I haven't heard back I'll split the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.