+ Reply to Thread
Results 1 to 6 of 6

Formula to VBA code

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2010
    Location
    India
    MS-Off Ver
    Microsoft Office Excel 2003
    Posts
    83

    Formula to VBA code

    Friends,

    I am just using the below ROUND function to avoid the decimals in my excel.
    =ROUND((((S4/X4)/3600)/9),0)

    Can anyone help me to write the same formula in VBA coding.

    Thanks,
    Saky
    Last edited by Saky; 12-03-2010 at 12:01 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Formula to VBA code

    Why do you want it in VBA, how will you use it?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-17-2010
    Location
    India
    MS-Off Ver
    Microsoft Office Excel 2003
    Posts
    83

    Re: Formula to VBA code

    Quote Originally Posted by royUK View Post
    Why do you want it in VBA, how will you use it?
    Roy,

    I am just having a try in converting all the simple formulas to VBA code. For simple multiplication i have converted to a VBA code like

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim isect As Range
    
        If Target.Cells.Count > 1 Then Exit Sub
    
        On Error GoTo ResetApplication
        Application.EnableEvents = False
    
        Set isect = Intersect(Target, Range("O3:O20"))
        
            If Not isect Is Nothing Then
            If Target <> "" Then
                Range("Q" & Target.Row) = Target * 60
            Else
                Range("Q" & Target.Row) = ""
            End If
        End If
    ResetApplication:
        Err.Clear
        On Error GoTo 0
        Application.EnableEvents = True
        Set isect = Nothing
    End Sub
    So as the same way i need to convert the formula into code...Is that can be done using VBA.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Formula to VBA code

    Why covert formulas to VBA, they will be more efficient as formulas

  5. #5
    Registered User
    Join Date
    11-17-2010
    Location
    India
    MS-Off Ver
    Microsoft Office Excel 2003
    Posts
    83

    Re: Formula to VBA code

    Pasting down the formulas more than 1000 cells makes the excel very untidy and once the formula is deleted by mistake then that particular cell will not work...so to avoid such cases i want every formulas to work at the backend.

    So that is the reason i am trying to convert it into VBA codes..

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Formula to VBA code

    Have you not heard of Sheet protection?

    Formulas will autofill if your data is in a proper table format & your excel settings are correct

    Tools -> Options ->Edit-> "extend data range formats & formulas.

    Or as you are using Excel 2003 set your data as a List,

    Data-> List -> create List

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1