+ Reply to Thread
Results 1 to 4 of 4

need help with VBA syntax

  1. #1
    Registered User
    Join Date
    07-05-2011
    Location
    ohio
    MS-Off Ver
    Home and Business 2010
    Posts
    5

    need help with VBA syntax

    I'm new to VBA and writing macros, and I'm not familiar with the proper syntax for generating my own code. I would really appreciate some help with this, it would make life a lot easier if I could write a macro to do what I'm currently doing with formulas.

    Lets say I'm using the following formula, which I have pasted all down column D. Based on whatever row we've pasted this into, were going to see whats in column B, then check whats in column C, then check to see if I2 contains anything (this is a box I use to switch between metric and standard), and based on all this criteria, we output something like:

    whateverswritteninB3 (0.000)
    Please Login or Register  to view this content.

    I'd like to do this in VBA, and while I dont know the proper syntax, the way I'm thinking about it in my head is:
    Please Login or Register  to view this content.
    Last edited by cbrf23; 07-05-2011 at 02:07 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,153

    Re: need help with VBA syntax

    Please Login or Register  to view this content.

    Just make sure the formula works, which it didn't and then record a macro.

    Put the cursor in the cell with the formula, press F2 to go into edit mode, press Enter to confirm the formula and stop the recording.

    What you get is raw code but I've tidied it up a bit.


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-05-2011
    Location
    ohio
    MS-Off Ver
    Home and Business 2010
    Posts
    5

    Re: need help with VBA syntax

    Hi TMShucks,

    I appreciate the effort, but that really is not what I'm looking for... Thats still using the excel if function, which I was trying to get away from. Also, it doesnt simplify anything for me, or make things any easier.


    I'm trying to write the macro in VBA and use the if/elseif syntax, since it is easier to read and edit, can contain more complex actions without getting extremely difficult to read, and I can then use in a worksheet sub to monitor changes and then automatically run functions when a change is made in a certain range.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,153

    Re: need help with VBA syntax

    I'm really not sure what you are trying to achieve, but the basic code is:

    Please Login or Register  to view this content.

    And:

    Please Login or Register  to view this content.

    is:

    Please Login or Register  to view this content.


    Do what you will with the string result.

    Regards
    Last edited by TMS; 07-05-2011 at 05:00 PM.

+ 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