Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Search Search
Search for:
Tech Support Guy > > >

Using a VBA function to place values or formulas into cells


(!)

mcmcman's Avatar
mcmcman mcmcman is offline
Junior Member with 2 posts.
THREAD STARTER
 
Join Date: Sep 2003
16-Sep-2003, 12:24 PM #1
Using a VBA function to place values or formulas into cells
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?
dtech10's Avatar
dtech10 dtech10 is offline
Member with 53 posts.
 
Join Date: Jan 2003
05-Oct-2003, 05:45 PM #2
Formula's ect if macros
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
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑