VB.Net - Excel Sum Column Values Referencing Column With A Variable

Good Day Experts!

I am having a bit of trouble here trying to figure out my SUM formula using variable for the column.  I can figure it out with a variable for the row end.

This works if I hard code the Column:

oSheet.Cells(DataRow + 2, ColumnStart).Formula = "=SUM(C7:C" & (DataRow) & ")"

Is it possible to use variable on Column reference?

Who is Participating?
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.

If the column variable is a string then you can do it this way

oSheet.Cells(DataRow + 2, ColumnStart).Formula = "=SUM(" & column & "7:" & Column & DataRow & ")"

Or if its a number

    Column = 4
    oSheet.Cells(DataRow + 2, ColumnStart).Formula .Formula = "=SUM(" & Range(Cells(1, Column), Cells(7, Column)).Address(False, False) & ")"

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
Jimbo99999Author Commented:
Thanks CholesDad...I will try it now!
I have just noticed that I have an extra .Formula in the number part. This should be removed.
Jimbo99999Author Commented:
It is working now!

Thanks for helping.  

I have several other Excel formatting things I will need to be doing, but this is good to get it out of the way.

Thanks again,
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.

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.