1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Using a VBA function to place values or formulas into cells

Discussion in 'Software Development' started by mcmcman, Sep 16, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. mcmcman

    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?
     
  2. dtech10

    dtech10

    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
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/165236