+ Reply to Thread
Results 1 to 11 of 11

VBA Inserts "NM" instead of 0""

Hybrid View

  1. #1
    Registered User
    Join Date
    11-14-2008
    Location
    Nashua
    Posts
    19

    VBA Inserts "NM" instead of 0""

    So I macro that should grab the existing cell formula and then wrap it with an iferror, but instead of inserting a 0 into the iferror formula it inserts "NM".

    Sub InsertIfError()
    '
    ' InsertIfError Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+E
    '
    Dim c As Range
        
        For Each c In Selection
            c.forumla = "=iferror(" & c.Formula & ", 0 )"
        Next c
        
    End Sub
    For example if the cell formula is "=A1+B1" and I run the macro it will insert "=iferror(A1+B1,"NM")"

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: VBA Inserts "NM" instead of 0""

    Try
    Sub InsertIfError()
    '
    ' InsertIfError Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+E
    '
        Dim c           As Range
        Dim f           As String
    
        For Each c In Selection
            f = Mid(c.Formula, 2)
            c.Formula = "=iferror(" & f & ", 0 )"
        Next c
    
    End Sub

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: VBA Inserts "NM" instead of 0""

    Try:

    Sub InsertIfError()
    '
    ' InsertIfError Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+E
    '
    Dim c As Range
        
    For Each c In Selection
        c.Formula = _
            "=iferror(" & Right(c.Formula, Len(c.Formula) - 1) & ", 0 )"
    Next c
        
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    11-14-2008
    Location
    Nashua
    Posts
    19

    Re: VBA Inserts "NM" instead of 0""

    Weird they all insert that "NM" instead. I'm clueless.

    I even tried:

    Dim c As Range
    Dim f As String
    
        
    For Each c In Selection
        f = "Iferror(" & c.Formula & ", 0 )"
        c.Formula = f
    Next c
        
    End Sub

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: VBA Inserts "NM" instead of 0""

    Please post a sample workbook.

  6. #6
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: VBA Inserts "NM" instead of 0""

    Does this happen with all workbooks/worksheets?
    Good luck.

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA Inserts "NM" instead of 0""

    I don't know if this is what you are after, but try this.

    Sub InsertIfError()
    '
    ' InsertIfError Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+E
    '
    Dim c As Range
    Dim rng As Range
    Dim i As String
    
        Set rng = Range("A1:A22")
        
            For Each c In rng
               i = c.Formula
               i = Right(i, Len(i) - 1)
               c = "=IFERROR(" & i & " , ""0"")"
               
            Next c
        
    End Sub
    Last edited by JapanDave; 02-06-2012 at 07:35 AM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  8. #8
    Registered User
    Join Date
    11-14-2008
    Location
    Nashua
    Posts
    19

    Re: VBA Inserts "NM" instead of 0""

    OK so If I run the macro with the hotkey setup it inserts the "NM" but if I manually launch the sub it works fine.
    Attached Files Attached Files
    Last edited by prescient; 02-06-2012 at 01:42 PM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: VBA Inserts "NM" instead of 0""

    Both of these routines work when run manually, the first by selecting a range initially.

    I see no reason why they would work differently from a short cut key. Unless you have changed which macro the short cut key links to, you may well be running your original code.

    The second one definitely works eith Ctrl-Shift-E

    Sub InsertIfError_TMS_Select()
    '
    Dim c As Range
        
    For Each c In Selection
        c.Formula = _
            "=iferror(" & Right(c.Formula, Len(c.Formula) - 1) & ", 0 )"
    Next c
        
    End Sub


    Sub InsertIfError_TMS_Range()
    '
    Dim c As Range
        
    For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
        c.Formula = _
            "=iferror(" & Right(c.Formula, Len(c.Formula) - 1) & ", 0 )"
    Next c
        
    End Sub

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: VBA Inserts "NM" instead of 0""

    Forgot to mention; the only time NM appears is in the existing formula.

    Regards, TMS

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: VBA Inserts "NM" instead of 0""

    The macro in the workbook does not appear to be assigned to a shortcut key.

+ 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