+ Reply to Thread
Results 1 to 8 of 8

using a formula within a macro

  1. #1
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    using a formula within a macro

    dont know if this is even possible but i would like to use a formula within a macro and have it run every time the workbook is opened. the formula would do the following

    if(e21+56>=an21)then delete contents of cell f21

    at the moment i have to check through and delete these manually for 700 rows every week, quite time consuming as you can imagine so if i could automate it, it would save me a lot of hassle

    any ideas greatly appreciated

    thanks

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: using a formula within a macro

    Hello jimb,

    Are you wanting this calculation to occur on hundreds of rows at once (e.g. rows 1:700), or only on row 21 when you open the file?

  3. #3
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    Re: using a formula within a macro

    on all rows in sheet which can vary week to week

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

    Re: using a formula within a macro

    This is a simple macro for the test, run it on-demand when you open your sheet.
    Please Login or Register  to view this content.
    I'm checking column E for the last value/last row. You can change that to any column you wish.
    _________________
    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!)

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: using a formula within a macro

    Note: Because you're not deleting or moving rows during the macro, you don't need to use
    Please Login or Register  to view this content.
    You could simply use
    Please Login or Register  to view this content.
    When deleting rows, it's best to go in reverse so as to avoid skipping rows as the value of i increases yet the number of rows decreases.


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

    Re: using a formula within a macro

    Yeah, I read the original question wrong and when i fixed it, forget to reset the direction. Rookie error, though the macro will still work ... backwards!


  7. #7
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    Re: using a formula within a macro

    thanks for the help but i tried this and am getting runtime error type mismatch with the following highlighted any ideas?

    If Cells(i, "E").Value + 112 = Cells(i, "AN").Value Then _

    i cant see anything wrong

    by the way my original count was wrong so i changed 56 to 112 ( number of days in 16 weeks) this wouldnt have made a difference would it?

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

    Re: using a formula within a macro

    It could make a difference. Math is math, so that's not the problem, the issue would be the sheet or the data, I imagine.

    Click on GO ADVANCED and use the paperclip icon to post up your misbehaving sheet and I will look it over.

+ 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