creating formula in excel

L

Luis Pedro

Dear all,
I've been trying to write a small program that creates an excel
file with some contents. I'm able to write "regular" strings in the
excel cells but I'm not being able to write complex formulas, e.g.
when they have commas to separate the different arguments.

I use:
xlBook.Worksheets(xlWorksheet).range(xlCellName).Value =
xlCellContents

where xCellContents is a String. Also tried
xlBook.Worksheets(xlWorksheet).range(xlCellName).Formula=
xlCellContents

but in both cases I get an exception:

HRESULT : 0x800A03EC

Any hint?

Thanks very much in advance for your time

Luis Pedro
 
G

Gary''s Student

Hi luis:

Take a look at:

Sub luis()
Dim xlBook As String, slWorksheet As String, xlCellName As String
Dim xlCellContexts As String

xlBook = "Book1"
xlWorkshet = "Sheet1"
xlCellName = "B9"
xlCellContents = "=Sum(A2:G2)"

Workbooks(xlBook).Worksheets(xlWorkshet).Range(xlCellName).Formula =
xlCellContents

End Sub

Note I had to change xlWorksheet into xlWorkshet to avoid using a reserved
word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top