+ Reply to Thread
Results 1 to 7 of 7

Conditionally populate cells in a column with a formula

  1. #1
    Registered User
    Join Date
    12-18-2014
    Location
    California
    MS-Off Ver
    Mac 2011
    Posts
    12

    Conditionally populate cells in a column with a formula

    For example, I have a dollar amount in column A and a currency in column B. If column B is any currency other than USD, I want column C to calculate something, but if the currency is USD, then no formula is needed. The only way I know to do this is to just write a formula that leaves column C blank if the currency is USD and paste it down to infinity. But is there a way to have excel selectively put the formula in based on my requirements, sort of like how conditional formatting will format cells based on certain requirements. My current solution works, but having that formula copied all the way down makes my workbook huge and slow.

    Thanks in advance.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Conditionally populate cells in a column with a formula

    You are talking about a sheet change event.

    I will write something to get you started.

    to start with use the macro recorder to record your formula.

    Select developer
    select start recorder

    type your formula into column c

    select stop recorder

    select macro,

    select your macro

    select edit, copy the formula from your macro.

    right click on the sheet name at the bottom of excel and paste the formula there
    instead of my formula.

    Close the vba window and enter a currency in column B.



    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 12-18-2014 at 09:10 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-18-2014
    Location
    California
    MS-Off Ver
    Mac 2011
    Posts
    12

    Re: Conditionally populate cells in a column with a formula

    Hi, thanks for the help, though, I should note a few things here:
    1. I am not very familiar with vba so forgive me if my questions are rudimentary.
    2. I'm not quite sure what you mean by "right click on the sheet name at the bottom of excel and paste the formula there." When I right click the sheet name, there are no paste options.
    3. I simplified my situation a bit in my question. Rather than columns A, B, C, I actually have them in H, I, P respectively. I don't know if that would affect the code you wrote but I feel like it would.

    Thanks.
    Last edited by Joe26; 12-18-2014 at 10:29 PM.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Conditionally populate cells in a column with a formula

    whats the formula you are using and how many rows? cant see it being that heavy on a workshhet
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    12-18-2014
    Location
    California
    MS-Off Ver
    Mac 2011
    Posts
    12

    Re: Conditionally populate cells in a column with a formula

    =IF(OR(I3="USD",I3=""),"",ROUND(O3/H3,4)&" USD/"&I3)

    It's not the formula itself, just the fact that it's copied all the way down (~1million rows). It makes my workbook go from 500k to 10MB, and it's much slower now. Granted my computer is a little old but still, it ran just fine before but now everything takes forever.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Conditionally populate cells in a column with a formula

    have you really ~1million rows? in use
    Last edited by martindwilson; 12-18-2014 at 11:03 PM.

  7. #7
    Registered User
    Join Date
    12-18-2014
    Location
    California
    MS-Off Ver
    Mac 2011
    Posts
    12

    Re: Conditionally populate cells in a column with a formula

    Well no, I'm not using all 1 million rows (now), but I copied the formula all the way down to the bottom (1,048,576) so as I keep adding more rows, I won't have to ever worry about repasting it again. I suppose I could just paste it down a few thousand rows, but once I reach that last row, I'd have to paste it down again. It's just an inconvenience that would be nice to get around.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Populate Blank Cells in Column F with formula
    By LarryJ79 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2013, 12:59 PM
  2. [SOLVED] Macro to Conditionally Format matching column/row cells in a grid.
    By Barking_Mad in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-28-2013, 10:35 AM
  3. Replies: 23
    Last Post: 09-25-2009, 07:39 PM
  4. Replies: 1
    Last Post: 09-19-2009, 08:09 PM
  5. Replies: 3
    Last Post: 08-07-2009, 12:03 PM

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