+ Reply to Thread
Results 1 to 9 of 9

VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

  1. #1
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    Red face VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    HELP! I have a Spreadsheet in which Columns F & G retrieve the Month (F) and Year (G) of the date in column E.

    The formula is as follows:
    =IF(ISBLANK($E2),"",VLOOKUP(MONTH($E2),Months,2,FALSE))

    Problem: Spreadsheet lags due to Formulas sitting in cells of COlumn F & waiting for a value to be inputed beside them.

    What I need: I want to remove the formulas i have in columns f and g and have a vba code that will populate F & G with this formula =VLOOKUP(MONTH($E2),Months,2,FALSE)) for every cell that is not blank in COlumn e.

    Meaning,
    If E2 is blank, then no formula in F2 or G2
    if E2 is not blank, F2 & G2 calculate Month and Year (Respectively).
    for every row in my range...

    Gracias in advance!

    PS- I have a dynamic range that auto arranges itself, so the code could be to just apply it within that range when ever a change is made to the worksheet? (i could be way off, just a suggestion).
    Last edited by DoriBeE; 03-03-2011 at 12:03 PM. Reason: close enough!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    Hi DoriBeE,

    Find the attached with what I think you want. It is a sample workbook. When you put a Date in a cell in Column E an Event Macro will fire and put formulas in F and G.

    If this isn't it, let me know...
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    Hi, this is Exactly what I need! the only problem is i have a vlookup function on mine to return the abbreviated name of the month rather than the #. (i need it for a pivot report). I can't get the Vlookup function to work with yours... It runs but then gives me an error.

    I'm almost certain i'm putting the quotations in the wrong parts of the formula...
    I'm using:
    Cells(Target.Row, "F").Formula = "=IF(ISBLANK($E" & Target.Row & "),"""",vlookup(MONTH($E" & Target.Row & "),Months,2,false)"
    "Months" being my Month's table/range

    Is this going to update Columns F & G entirely every time a change is made to column E? or does it just fill in that target row? My screen jumped like the spreadsheet was doing too much to calculate and i'm only at 155 rows...

    would applications.screenupdate = false keep it from doing that?

  4. #4
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    Do i need "If is blank" ? the code only kicks in if a change is made to column E... Can't i just throw in an

    Else if Target.Value = VbNullString then
    Exit sub
    end if


    under it and remove the if is blank for the formula quote, leaving only the vlookup?

    Last edited by DoriBeE; 02-11-2011 at 07:23 PM. Reason: Had a better idea for the else if formula.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    Hi,
    ScreenUpdating will make things go faster. Be sure to turn it back on at the bottom.

    For the Formula Quote problem. I always make the darn formula work on the spreadsheet and copy and paste it into my VBA. Everywhere there is a single quote I double it. (Put an extra quote).

    I never understood why you wanted a vlookup for the Month and Year. If you are using your dates in a pivot table why don't you simply group the dates by Year and Month instead of trying to extract it?
    See http://chandoo.org/wp/2009/11/17/gro...-pivot-tables/

  6. #6
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    That link is actually very usefull, i wasn't aware Pivots did that.

    It won't let me group some of the dates though, keeps saying "cannot group that selection". It worked for the Order REquest Dates but not for the Orders created.

    The pivot comapares Requests vs created by year, then month then gives a total for each. HA if I could get it to work this would be perfect. I'd save my self a few columns of space on the ws and wouldn't have to use this formula.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    I find if it can't group by date, you have some non-date data in the column. Blanks in the date column also keep it from grouping by date.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    Quote Originally Posted by DoriBeE
    It won't let me group some of the dates though, keeps saying "cannot group that selection".
    In general terms see: http://www.contextures.com/xlpivot07.html#Problems

  9. #9
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    Re: VBA - Populate Cell in Column F if Adjacent cell in Column E is not blank

    how do i avoid the runtime 13 (type mismatch) error when an entire row is deleted?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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