+ Reply to Thread
Results 1 to 6 of 6

VBA Macro for Removing #N/As

  1. #1
    Registered User
    Join Date
    09-22-2020
    Location
    France
    MS-Off Ver
    365
    Posts
    2

    VBA Macro for Removing #N/As

    Hi all,

    I just registered to the forum so nice to meet you all. Before we start, a little bit of my background so you can know who you're helping. I'm a 24yo french finance master's degree student. I'm currently doing my master's thesis whose subject is mutual funds' performance and fees. I basically want to know if an investor who pays more fees will receive more performance, as fund managers claim fees such as management fees are the reflect of their skills.
    So to be able to show whether fees and performance are positively correlated or not, I downloaded a massive database with 10k funds and their monthly NAV (or price) starting from January 2004 (so roughly 200 observations/fund). Now of course, I have lots of #N/A in my database and for 2 reasons :
    - market was closed that day
    - or the fund was not alive yet
    I would like to clean that database and get rid off these #N/As. To do so, I want to target each #N/As that are comprised between 2 values and use the average of these 2 values to replace the #N/A.

    I just wrote a VBA code to help me do that quickly but it doesn't work :

    Please Login or Register  to view this content.
    Here is a snapshot of what my excel look like :

    LP61500731 LP61501237 LP61500989 LP61501059 LP40209239 LP40209256
    Net Asset Value 31/08/2020 51.44 30.01 18.30 13.43 11.78 14.13
    Net Asset Value 31/07/2020 52.48 30.65 18.63 13.71 10.94 13.45
    Net Asset Value 30/06/2020 52.77 30.75 18.70 13.64 10.42 12.84
    Net Asset Value 29/05/2020 52.96 30.79 18.74 13.39 10.06 12.65
    Net Asset Value 30/04/2020 51.78 29.99 #N/A 12.95 9.57 12.07
    Net Asset Value 31/03/2020 44.53 25.96 15.74 11.67 8.52 11.13
    Net Asset Value 28/02/2020 52.21 30.00 18.38 13.18 #N/A 12.60
    Net Asset Value 31/01/2020 58.71 33.51 20.60 14.06 12.48 13.68
    Net Asset Value 30/12/2019 61.57 34.98 21.52 15.20 13.07 13.63

    Hope someone understands my problem and can give me any clue about how to solve it

    Have a wonderful day,

    Alexis
    Last edited by davesexcel; 09-22-2020 at 11:02 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Macro for Removing #N/As

    Try the replace function

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-22-2020
    Location
    France
    MS-Off Ver
    365
    Posts
    2

    Re: VBA Macro for Removing #N/As

    Just noticed I copy paste the wrong code. Here is what I meant :

    Please Login or Register  to view this content.

    True to say the replacement function is particularly efficient at spotting the #N/A but what I would like to do is replace each one by the average of the above and the below values.

    I thought my code would work but it doesn't..

    Best
    Last edited by davesexcel; 09-22-2020 at 12:45 PM.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Macro for Removing #N/As

    Try using text instead.
    You can reduce the loop as well, to start at row3 and column 3
    Please Login or Register  to view this content.

    You can also use specialcells() to find errors
    Please Login or Register  to view this content.
    Last edited by davesexcel; 09-22-2020 at 01:06 PM.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: VBA Macro for Removing #N/As

    Quote Originally Posted by davesexcel View Post
    You can also use specialcells() to find errors
    Please Login or Register  to view this content.
    Usually #N/A errors are generated by formulas, so you might want to suggest xlFormulas in place of the xlCellTypeConstants in you code. As a side note, the xlCellTypeConstants argument can also be written xlConstants and it will work also.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Macro for Removing #N/As

    I was surprised it worked as well when I tested it.
    I copied the OP's data and it worked as expected, that is why I shared it.

+ 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. removing punctuation macro
    By dorabajji in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2020, 06:18 PM
  2. [SOLVED] removing a macro from routine
    By chubbychub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2016, 05:44 PM
  3. Removing Input Box from Macro
    By luckyajr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2012, 06:26 PM
  4. Macro for Removing Rows?
    By RecRic in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2007, 08:32 AM
  5. Removing macro
    By news in forum Excel General
    Replies: 2
    Last Post: 05-27-2006, 08:10 AM
  6. Removing a macro
    By Clark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2006, 09:45 PM
  7. Removing macro
    By Junkman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-11-2006, 11:15 AM

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