If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Insert formulas from VB array..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-02-04, 15:49
REGINALDM REGINALDM is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
Insert formulas from VB array..

I have been trying to get an array full of formulas to insert into a range on excel spreadsheat; however the formulas end up showing as text and not evaluating. I have tried sever different commands and none seem to work. I currently am outputing one cell's formula at a time but this is painfully slow and i was hoping to improve speed by storing them in an array and puting out the whole array of formulas at one time. Is this possible? and if it is how can it be done. range.formula = array does not seem to work.

Last edited by REGINALDM; 04-05-04 at 08:03.
Reply With Quote
  #2 (permalink)  
Old 04-04-04, 21:58
Smitty Smitty is offline
Registered User
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 153
Welcome to the Board!

Can you post your code?

Smitty
Reply With Quote
  #3 (permalink)  
Old 04-05-04, 11:36
REGINALDM REGINALDM is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
I am actually doing this is access, and I created a test procedure to try and get it to work here is the code of my test procedure. It is simply code for a form that has one button on it. could be cut and paste into VB if you wish.


Dim objApp As Excel.Application
Dim objBook As Excel.Workbook


Private Sub Button1_Click()
Dim objBooks As Excel.Workbooks
Dim objSheets As Excel.Sheets
Dim objSheet As Excel.Worksheet
Dim range As Excel.range
'Create an array.
Dim saRet(5, 5) As String

' Create a new instance of Excel and start a new workbook.
Set objApp = New Excel.Application
Set objBooks = objApp.Workbooks
Set objBook = objBooks.Add
Set objSheets = objBook.Worksheets
Set objSheet = objSheets(1)


Set range = objSheet.range("A1", "E5")
Set range = range.Resize(5, 5)
For iRow = 0 To 5
For iCol = 0 To 5
If iRow = 0 Then
saRet(iRow, iCol) = iCol
Else
saRet(iRow, iCol) = "=SUM(" & Chr(65 + iCol) & iRow & ":" & Chr(65 + iCol) & iRow & ")"
End If

Next iCol
Next iRow

'Set the range value to the array.
range.Formula = saRet
objBook.SaveAs "c:\test.xls"
'Return control of Excel to the user.
objApp.Visible = True
objApp.UserControl = True

'Clean up a little.
Set range = Nothing
Set objSheet = Nothing
Set objSheets = Nothing
Set objBooks = Nothing
End Sub
Reply With Quote
  #4 (permalink)  
Old 04-07-04, 17:01
REGINALDM REGINALDM is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
Just incase anyone wants to know i figured out my problem. It waws that i simply had to declare the array as a varient instead of a string
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On