Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 19th, 2004, 06:05 AM
Authorized User
 
Join Date: Jan 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Converting Excel formulae to VB

Hello there,

I have been given a spreadsheet with many complex formulae in the cells.

My task is to write some VB (in a DLL, but that is immaterial) that replicates the behaviour of these formulae.

Can you tell me - is there a utility (either within Excel or "off-the-shelf") that will convert these GHASTLY-looking things (i.e. nested nested nested IF statements and other rubbish all on one line) into a VB code snippet (or psuedo-code snippet).

This would GREATLY help me in this conversion process.

Thanks.

James

P.S. On a related topic - My Excel skills are very limited. I presume there are "best practice" guidelines for writing formulae in cells, so as to avoid "spaghetti formulae" everywhere. But I don't know anything about this, really. I would like to suggest to the person writing the original spreadsheet that these cells and formulae are written/structured rather poorly - but I don't know if that is true or not! Please can you tell me if there are generally-accepted ways of creating sheets to avoid "spaghetti formulae"? Thanks.

//##
 
Old March 21st, 2004, 08:48 PM
Authorized User
 
Join Date: Oct 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem (if you can call it that) with excel formula is exactly as you point out. You can fit very complex (spagetti) formula on one line. As far as "best practice" is concerned, sometimes it is tidier to have as few formula as possible on the spreadsheet resulting in, well, spagetti. But as long as the spreadsheet also contains detailed comments explaining the formula, this isn't necessarily a problem.

I don't know of any off the shelf utilities that will convert your excel formula into VB.

 
Old April 24th, 2004, 10:21 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Mike D
Default


 You can enter a formula in VBA excel in the following way:

  Location = " formula "

  Example:

  ' Paste formula
        Range ("$M$10") = "= (SUMIF("$B$10:B$113","$L10","$K$10:$K$113")))"

  Or

  ' Paste formula
        Range(B_Str(4)) = _
        "=IF((SUMIF(" & B_Str(1) & "," & B_Str(2) & "," & B_Str(3) & _
        ")=0),"""",(SUMIF(" & B_Str(1) & "," & B_Str(2) & "," & B_Str(3) & ")))"


  Remember that two quote signs are doubled in the string: ( """" ) as above.



 
Old May 11th, 2004, 06:23 AM
Authorized User
 
Join Date: Jan 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.

I have found the best way to do this is simply to paste the formula into Notepad, then turn it into pseudo-VB manually, by examining it bit by bit and inserting the necessary line-breaks and tabs to make it more readable. I then take that as a basis from which to write my real VB equivalent.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting the DTS file execution from vb to vb . ankur.nagdeve .NET Framework 2.0 0 February 27th, 2008 05:12 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
Converting VBA Excel to VB.Net. Help help. dinosaur_uk VB.NET 2002/2003 Basics 4 October 5th, 2004 04:58 PM
Offset Formulae aspadda Excel VBA 3 January 6th, 2004 02:09 PM
converting DTS package from VB 6 to VB .NET petroleo Pro VB Databases 0 August 18th, 2003 05:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.