+ Reply to Thread
Results 1 to 5 of 5

VBA Constants and Variables

  1. #1
    Registered User
    Join Date
    11-05-2010
    Location
    Aberdeen
    MS-Off Ver
    Excel 2003
    Posts
    1

    VBA Constants and Variables

    Hello,

    I am fairly experenced excel user but I am relatively new to VBA (only started using it a couple of weeks ago).

    I am currently trying to build a engineering spreadsheet for the design of foundations. this requires alot of functions and calculations.

    What i am looking to do is use the spreadsheet as an input and output area only and carry out all the calculations in VBA so i want to refer to the spreadsheet as little as possible in the code.

    My Idea to do this was to create a module with all the input parameters for the calculations that are required which would pick the values of the parameters from the values entered into the spreadsheet cells, these parameters could then be used throughout the programme code without having to refer back to the spreadsheet again.

    One way I this this was expressing each parameter as a funtion e.g
    Please Login or Register  to view this content.
    This works but seems to stop the spreadsheet updating automatically.

    Ive tried using varibale and constants but theu dont allow you to refer to the spreadsheet.

    I hope someone can help, this has been annoying me for the last couple of days

    Thanks
    Ian
    Last edited by royUK; 11-05-2010 at 05:16 AM. Reason: add code tags

  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: VBA Constants and Variables

    Why not use excel's inbuilt Functions as much as possible, that would be much more efficient than using VBA
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: VBA Constants and Variables

    The function will only update if you add a line to tell excel the function is volatile.

    Please Login or Register  to view this content.
    Note that using the Volatile approach can make the workbook slow if there a lots of calculations.

    If your function includes an argument that is linked to a cell then it will update automatically.

    Useful site for engineering related excel things
    http://newtonexcelbach.wordpress.com/
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA Constants and Variables

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    11-05-2010
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA Constants and Variables

    Ian - I'm the author of the blog that Andy linked to.

    If you have a look at some of my spreadsheets posted there you'll see that I make a lot of use of VBA User Defined Functions. I definitely disagree that using the built in functions is necessarily more efficient. Using VBA is often more efficient, and is also likely to be more flexible and more robust.

    In your example I'm not sure why you would write that as a function, rather than just using:
    dia = Range("dia").value
    in the code.

    I tend to use variant arrays for data input; e.g.

    Please Login or Register  to view this content.
    Note that:
    • Checking that InputData is a range allows the function to be used as a UDF, or called from VBA.
    • "Range" is case sensitive.
    • .Value2 works quicker than .Value (it dumps some formatting information you don't need anyway)
    • You can assign a VBA array to the function return value (which must be a variant). This array can then be used in another VBA routine, or returned to the spreadsheet by entering as an array function.

    Please ask if you need more details of anything.

    Andy - thanks for your support for the blog!

+ 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