Using a VBA function to place values or formulas into cells

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

mcmcman

Thread Starter
Joined
Sep 15, 2003
Messages
2
Hi,

I have been trying to figure out if it is possible to use a VBA function to place values and formulas into excel cells. In the past, I have done so using Macros, but for my particular application, I want to be able to do so from within a VBA function. Any ideas on how to do this?
 
Joined
Jan 31, 2003
Messages
53
Hi
This might give you some ideas.


Sub FormulaInCells()
Dim MyRange As Range
Dim Total As Integer

'Setup Range Pointer
Set MyRange = ActiveSheet.Range("b1:b10")

'Placing Formula's in Range
With MyRange
.Formula = "=int(rand()*10)"
End With

'Using Excel Functions on a Range
MsgBox ("Sum Data & Autofit")
Total = Application.Sum(MyRange)
Range("a11").Value = "Total"
Range("b11").Value = Total
Range("b1:b11").Columns.AutoFit

'Restore Worksheet
MsgBox "Restore Worksheet"
RestoreWorksheet
End Sub
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top