+ Reply to Thread
Results 1 to 10 of 10

Enter Formula using a Macro

  1. #1
    Registered User
    Join Date
    11-15-2009
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    24

    Enter Formula using a Macro

    Hi,

    I am trying to write a macro which will get values from column B and C and print the result on column D using a simple function like the one before:

    D2 = "text" & B2 & "text2" & C2 & "text3"

    I need this to be done in the macro, so that when I click the button, it will automatically create column D. Column B is formula and column C is constants.

    I tried something like the one below:

    Please Login or Register  to view this content.
    What am I doing wrong? Does anybody have an idea?

    Thanks.
    Last edited by excelgenius; 11-16-2009 at 03:50 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Is there a solution for this?

    Quote Originally Posted by excelgenius View Post
    What am I doing wrong? Does anybody have an idea?
    First thing you're doing wrong is breaking the forum rules regarding thread titles. Oops.

    Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to EDIT that post above and change the thread title to one that matches the problem exactly. (you may have to click on GO ADVANCED to get to the thread title).

    Remember, thread titles form the basis of people "searching" the database to solve problems for themselves. So make sure your title matches the issue, not your emotional state. (wink)

    ============
    Then try this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    11-15-2009
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Enter Formula Using a Macro

    @JBeaucaire:

    Sorry for breaking rules, that wasn't my intention. I will read the rules at once. Thanks for the edit to the code, it worked just as I wanted.

    Cheers.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enter Formula using a Macro

    .Offset doesnt work properly with discontinous ranges.

    perhaps
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Enter Formula using a Macro

    If these suggestions takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Enter Formula using a Macro

    Quote Originally Posted by mikerickson
    .Offset doesnt work properly with discontinous ranges.
    Can you provide an example, Mike?
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enter Formula using a Macro

    If A1 = "x" , A2 is blank, A3 = "y" then running this code gives these results

    Please Login or Register  to view this content.
    It appears that .Offset returns the offset of the first area of a discontinous range rather than offsetting the whole range.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Enter Formula using a Macro

    Curiuos -- not on my computer:
    Please Login or Register  to view this content.
    Returns
    Please Login or Register  to view this content.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enter Formula using a Macro

    Its probably due to my Excel2004's VBAv.5 vs your VBAv.6.

    (I really hope that they put VBA back into Excel 2011 or whenever)

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Enter Formula using a Macro

    Reckon so.

    I know that there are a variety of properties and functions that relate only to the first area of a multi-area range, or can't cope at all. I figured one day when I got ambitious I'd try to tabulate a 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